+1 vote

So, I want to check for keys pressed. Particullary space key.
How do I do it in _process ?
the only way I found so far is to do this:

func _input(event):
    print(event.get_class() == 'InputEventKey') # To check if that's a key press event
    print(event.as_text() == 'Space') # to check if that's a space key

Which doesn't work for me. Is there a list of String key codes I can use for :

Input.is_action_just_pressed( ??? )

'space' and "Space" not working.

Thank you!

in Engine by (29 points)

2 Answers

+2 votes
Best answer
if event is InputEventKey:
    if event.scancode == KEY_SPACE:

List is in the @GlobalScope
under enum KeyList

You can't use them in is_action_just_pressed(). Actions and keys are different. Keys can be assigned to actions so they trigger them. Check "Project Settings / Input Map".

by (2,292 points)
selected by

Gotcha, thank you

0 votes

you could also use this to view the name of pressed key :)

  func _input(ev):
        if ev is InputEventKey :
by (73 points)

it will print twice in pressing a key once, 1 for pressed 1 for released

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 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 webmaster@godotengine.org with your username.