Newbie: how to get a key press event

:bust_in_silhouette: Reply From: Sdhy

Here’s how I do it:

func _ready():
    set_process_input(true) 
    ##This may or may not be required for inputs to work.

func _input(ev):
    if Input.is_key_pressed(KEY_K):
        do_your_thing()

I don’t really know how to use the ev thing.

You can do KEY_S or KEY_ENTER or KEY_KP_5 for 5 on the numpad, and lots more.

For more keyboard buttons to use, check this link out and scroll down:

Hope this helps.

You don’t need to set_process_input in Godot 3.0, it detects it automatically.

mateusak | 2018-02-12 13:52

That’s convenient. Thanks!

Sdhy | 2018-06-14 16:15

1 Like