GetKeyDown function as switch ... case instruction?

  1. Welcome to the Unity Forum and thank you for using CodeTags :slight_smile:
  2. It is a little frowned upon posting in very old threads.
  3. Using Input.inputString is not the way to go.
    As you have noticed, the documentation says:
    “Only ASCII characters are contained in the inputString.”
    This makes it ill-suited for the task of detecting key presses.

There are two InputSystems now, old (Input.) and new (InputSystem.)

OLD:
There are many (more recent) threads about how to get the currently pressed keys in the old input system. Like this thread.
To make along story short. There is no easy way to do this for every frame. Consensus seems to be that your best bet is to make a list of keys (KeyCode.*) and then check for those. You can derive that list from the KeyCode enum but you should do this only once, not every frame.

NEW:
The new InputSystem has an API to get the pressed key:

// Response to the first button press. Calls our delegate
// and then immediately stops listening.
InputSystem.onAnyButtonPress
    .CallOnce(ctrl => Debug.Log($"Button {ctrl} was pressed"));

Documentation: Class InputSystem | Input System | 1.4.4

Again, welcome to the Unity Forum :wink:

2 Likes