How to model input when many keys/most/all of keyboard will be used?

Godot Version



Hello! New to Godot and trying to make a game where basically all of the keyboard is used for input (imagine your pointer and middle finger walking across your keyboard–that’s going to be one of the core mechanics). While I know I can make keyboard mappings for every character, I feel like that may be a lot of tedious work. And for different keyboard layouts, that work would only multiply. Does anyone have any suggestions for modelling organizing the input in this case? Like a way where I can just have a list/array of keyboard characters and just instantiate packed scenes that will listen to the right things and create the relevant signals?


You can add actions and map them to keys in code with the InputMap class.

I’ve made a typing game from mostly InputEventKey, I am not sure how exactly you want to model your game, but you can avoid creating a wild input map.

func _input(event: InputEvent) -> void:
    if event is InputEventKey:
        # "walking" across a keyboard might make use of this
        event.physical_keycode == KEY_W
        # keycode needs some work for non-english/ascii keyboards but is a strong start
        event.keycode == KEY_W

Does GDScript have reflection capabilities so I wouldn’t need to enumerate all KEY_* enum values? E.g. It would be great if a scene could be parameterized with a letter and then the code could check event.physical_keycode == KEY_${letter} (of course, not sure what syntax is valid here). It seems KEY_`-prefixed constants are not keys in a Dictionary/Enum so I can’t do some of the subscription syntax I’m familiar with.

Oh I suppose I can do something with event.as_text() but I could see how that’s considered bad practice…

You can add to the keys for a while KEY_0 + 2 == KEY_2 same with letters KEY_A + 2 == KEY_C but after 9/Z it gets funky, as_text() is fine you can also use String.chr(event.keycode) without modifiers (shift/alt/ctrl).