Nathan Barraud
Nathan Barraud

Reputation: 21

Unity rebinded Keys names are wrong on azerty keyboard

So I have a working rebinder script, but the problem is when I want to display the rebinded keys names.

I am using the new unity input system

The code below returns the right names for a qwerty keyboard, but not for a azerty keyborad ! However, the bindings are correct, since the controls are working regardless of the keyboard layout. The only broken thing is the display, that is to say the value fed in the "UpdateText(string key)" void:

RebindSection[j].UpdateText(InputControlPath.ToHumanReadableString(
             Actions[j].action.bindings[bindingIndex].effectivePath,
             InputControlPath.HumanReadableStringOptions.OmitDevice));

Does anyone know how I can get the real name of the key and not the location of the key in us keyboard ?

Edit: I'm developing the game on ubuntu, And the script I wrote above works in the editor, but not in the builds...

Upvotes: 2

Views: 1352

Answers (1)

user3345048
user3345048

Reputation: 371

To put it bluntly, the Unity Engine uses physical key signal to detect inputs from the keyboard, but as it's kinda hard to guess what an "0100100" keyboard signal means, it puts a QWERTY-based tag on the key's signals so that we, devs, can at least have an idea of what is going on.

The only kinda-problem that comes from this approach is the differential keys that exist between the 2 types of keyboards such as the "< >" key right to the left shift key that doesn't always exists on the QWERTY keyboard. (Most AZERTY keyboards has a small left shift key and a key in-between it and the W key with "<>" while most QWERTY keyboards just have a wide Left Shift key that covers both key at once.)

That's where the physical key kinda hits a snag as, in such case, the "<>" of the AZERTY keyboard key is actually just... absent on the QWERTY keyboard. Unity can register the key (as it does have its own unique signal), but that would make the key inaccessible on a QWERTY keyboard. Those kind of keys are called "White Keys" in development jargon which has a kinda rule to "Never use those by default unless it's for action available elsewhere. Leave it to the user to define those if possible.".

If you want the actual keyboard-based key name, you can access the key string with the following code: Keyboard.current.KEYCODE.displayName

Replacing "KEYCODE" with the key name such as "aKey" which will give you the physical key located at "A" on a QWERTY keyboard based on your current keyboard language & layout.

Upvotes: 1

Related Questions