Godot Version
4.4, Linux/X11
Question
How to handle input of keys/characters that are triggered by a combination of keys?
Use case: I’d like to assign a special function to “keys” (actually characters) [<] and [>]. Preferably using Input assignment in Project Settings and actions (same as I do for all the other input).
Problem: In many keyboard layouts, these characters aren’t triggered by single keystrokes, but by combinations. E.g. in English layout, the two are typed by pressing [Shift]+[,] and [Shift]+[.] respectively. In German layout, it’s even worse, since both characters are placed on the same key, so pressing [<] alone produces “<”, and [Shift]+[<] produces “>”.
How I handle inputs in my game is that I add actions to project settings, assign them keys and in my code, I check for them by calling event.is_action_pressed('blahblah')
in _input
or _unhandled_input
functions.
I tried to make it work the same way for [<] and [>] by creating actions and assigning them with “Less” and “Greater”. But, whatever I try, I always end up getting InputEventKeys with keycode of basic keys (e.g. “Period”) and Shift modifier. Switching between physical/non-physical doesn’t help. Unicode seems to not work at all I tried _input, _unhandled_input, _unhandled_key_input, and _shortcut_input, but none of these seems to be aware that I’m pressing a combination.
What’s the Godot way of handling this kind of inputs?
(note: I’m aware that it’s kind of mixing concepts of “keys” and “characters”, and they’re not the same, but tbh players won’t care. If they’re told to “Press key [<]”, they’ll understand that they’re expected to press either a single key or a combination, depending on the layout they use)