+2 votes

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.

Godot version 3.4.4
in Engine by (25 points)

1 Answer

0 votes
Best answer

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.

by (50 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.