How to get locale label of Physical Key using Input Manager

This question is about the older Input Manager.

Unity added the Physical Key option in Unity 2021.2 and made it enabled by default in 2022.0.

I can’t find a way to get the locale-correct label from the KeyCode when this option is enabled. This affects Rewired because, on all platforms except Windows, Rewired depends on Input.GetKey for keyboard input. Even on Windows, the user has the option to disable native keyboard handling and fall back to UnityEngine.Input for keyboard input. If this option is enabled, and it is in all projects now by default, glyphs and help text can only match the US 101-key layout. An AZERTY keyboard for example will return KeyCode.A when the Q key is pressed. Displaying “Press A to do something” when the action is mapped to Q is wrong and will frustrate and confuse players.

Right now, my only option is to advise users to disable the Physical Key option. I am adding code to detect this and display a warning in the Rewired Input Manager if it is enabled.

I wanna make sure I understand. You said:

An AZERTY keyboard for example will return KeyCode.A when the Q key is pressed. Displaying “Press A to do something” when the action is mapped to Q is wrong and will frustrate and confuse players.

Is that backwards? Did you mean displaying “Press Q to do something” when the action is mapped to A is wrong and will frustrate and confuse players?

It sounds like you’re talking about the problem of being able to tell the player what key to press when the physical keys option has automatically remapped them. Is that correct? If so, I have the same question. The physical keys option is useless if it can’t also be used to remap the instructions.

I’m not sure what you mean by your last paragraph though. How can a user disable the physical keys option? I thought that was up to the developer.

Both are true.

On an AZERTY keyboard, If the Action is mapped to KeyCode.A, that corresponds to the physical key with a label of Q on the keyboard. Your help text only knows the KeyCode, not the key label. Therefore, your help text will show “Press A to do something,” when the user actually has to press Q.

There needs to be a function to lookup the label for the keycode. I doubt this will be added though, as UnityEngine.Input is now considered legacy.

Yes, and that was my point exactly. There is no way to get the key label so there is no way to show the user accurate instructions, making physical key mode problematic at best and useless at worst, and yet it is the default setting in Unity.

By “user,” I mean users of Rewired, my input system for Unity. They have to disable this option if they want to display key bindings to the player.