Hello and sorry in advance if my terminology is off! I'm working on a menu to let the player remap keys. I've got default keys in the project's InputMap, and then buttons to remap them, where:

on _Ready I get the InputEvent and set the label of the button to show the default key:

inputEventKey = (InputEventKey)InputMap.ActionGetEvents("jump")[0]; // get event from InputMap
Text = OS.GetKeycodeString(inputEventKey.PhysicalKeycode); // change label of button

And then on _UnhandledInput I change it like this:

if (_event is InputEventKey e)
{
	inputEventKey.Keycode = e.Keycode; // set new key in InputMap
	Text = OS.GetKeycodeString(e.KeyLabel); // change label of button
	...
}

This all seems to work fine, my problem is that I want to show key labels based on the player's keyboard layout. After I remap a key it does that, because I use e.KeyLabel instead of e.Keycode, but by default it shows the physical key name.

For example, I'm using a QWERTY keyboard and I have "Z (Physical)" in the InputMap. By default the button will say "Z", when I remap it to the (physically) same key, it will say "Y". I want it to show "Y" by default, but I don't know to get a key label just from the physical keycode/InputMap.

  • Nevermind, morning me is forgetful and last night me was right. The InputMap's InputEventKey only gives me the physical key, but no label (makes sense, why would the InputMap know a player's layout?): "Keycode":0,"PhysicalKeycode":69,"KeyLabel":0

    Edit and ignore the rest: keyboard_get_keycode_from_physical() does the job, I kept looking for keyboard_get_scancode_from_physical() before I remembered "scancode" got renamed 🤦 I think it also got moved from OS to DisplayServer which is why I couldn't find it. I assumed it was just missing in 4.2.

housatic changed the title to Get (localized) key label from physical keycode .

Okay, re-reading this in the morning and I think I'm just stupid. Both of the objects are InputEventKeys so I should be able to use KeyLabel in the _Ready just like I did on _Input. Will try again tonight

Nevermind, morning me is forgetful and last night me was right. The InputMap's InputEventKey only gives me the physical key, but no label (makes sense, why would the InputMap know a player's layout?): "Keycode":0,"PhysicalKeycode":69,"KeyLabel":0

Edit and ignore the rest: keyboard_get_keycode_from_physical() does the job, I kept looking for keyboard_get_scancode_from_physical() before I remembered "scancode" got renamed 🤦 I think it also got moved from OS to DisplayServer which is why I couldn't find it. I assumed it was just missing in 4.2.