How do I know which keyboard button is pressed without using 50+ if logics.

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

I am making a keyboard remap system.The player can press any button and map input to that button in_game.

I need to know which button the player pressed.
The alternative I see is to use more than 50 if statements or a for loop to loop through an array of each input.

Is there a variable that contains the last keypress(or combo) if it exists? I couldn’t find anything in the docs as well.

:bust_in_silhouette: Reply From: PoisonIvy

Not sure if this would work in your project, but the way I’d approach this would be to have a dictionary of key codes and their related actions

{"up": KEY_W, "down": KEY_S, etc.}

And then in your remap function you could have

func _input(event):
    if event is InputEventKey and event.pressed:
        keymap_dictionary[the_key_im_remapping] = event.scancode

It might change the way you need to get user input though.