- Home /
Question by
GlitchBait · Dec 20, 2016 at 12:29 AM ·
keyboard input
Get Input value?
For assigning custom or unknown input values from a Joystick/Throttle or a key pad, how can I get the key that the player pressed? How can I Debug.log the value of whatever input Unity finds? For example, Debug.Log(Input.anyKey.ToString()); returns True or False, but how can I have it return 'space' if I press the spacebar?
Comment
Best Answer
Answer by Geometrical · Dec 20, 2016 at 12:47 AM
I've written up a quick script for you:
using UnityEngine;
public class InputTest : MonoBehaviour {
private void Update() {
foreach (KeyCode keyCode in System.Enum.GetValues(KeyCode)) {
if (Input.GetKeyDown (keyCode)) {
Debug.Log ("Current input key:" + keyCode.ToString());
}
}
}
}
System.Enum.GetValues(typeof($$anonymous$$eyCode)) , but close enough! Thank you kindly.
Your answer
