The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Okay what I am doing is setting up a controls menu. Where the player can change the InputMap's actions. Example:

func _input(event):
    if event.is_action("ui_accept"):

I also want a preset menu where gdscript manually creates InputEvents. How ever I can't find out how to do that in gdscript. I've tried doing this, but KEY_W is only an int not an actually InputEvent.

func _on_create_preset_input_pressed():
    var new_input = KEY_W
in Engine by (272 points)
edited by

(SIDE NOTE) What is up with my formatting? i used /`/ why are tabs not showing properly?

for formatting multiline code correctly you have to leave a blank line and write everything with 4 blank spaces indentation extra. Something like this:

(blank line)
(four spaces)func _process(delta):
(four spaces)(four spaces) print("hola")

will render like this

func _process(delta):

Thank you. Now If only my real question was solved.

hi, i have a question... is only the seccond part what is not working? i mean, this?

func _on_create_preset_input_pressed():
    var new_input = KEY_W

Yes. _on_create_preset_input_pressed()

I posted an answer with the code you should use. It works for me.

Oh, i see you already found the answer.

3 Answers

+3 votes
Best answer

You can do this:

func _on_create_preset_input_pressed():
    var new_input =
by (3,505 points)
selected by
0 votes

Okay so Godot Has different ways of setting info on InputEvents.
For Input Event Key it's set_scancode and KEY_(WHATEVER)

For InputEventMouseButton it's set_button_index and BUTTON(WHATEVER) OR BUTTONWHEEL_(WHATEVER)

(For the complete list you can check the source code it's /core/os/input_event.cpp)

by (272 points)
0 votes

For people using the answers here:

I tried doing it with one line:
but my game kept crashing and I found out that I had to assign it to a variable first otherwise it doesn't work. Like so:
var event =

So be careful

by (26 points)
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.