How do I get a key's name?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Rubin

Hello! I want to make an interaction text like “Press F to interact” but with the key that the player has set to be the interaction input, not only F.

I’ve tried InputMap.get_action_list("interact")[0].as_text() but it doesn’t seem to work.

I’ve tried it and it works përfectly. Note, that this method doesen’t work with physical keys, so you need to make regular key input the first event of an action.

USBashka | 2022-07-15 18:42

:bust_in_silhouette: Reply From: USBashka

There is function to get human-readable key name — OS.get_scancode_string()
If you using physical keys, try this:

OS.get_scancode_string(InputMap.get_action_list("interact")[0].physical_scancode)

Elif you’re using regular keys, it’s better to use this:

OS.get_scancode_string(InputMap.get_action_list("interact")[0].physical_scancode)

If neither of them works, maybe the problem in something else. Post the code where you trying to use this text.

1 Like

Hi! Today we have the OS.get_keycode_string(key: Key) function!

1 Like