+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')
    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:
        pass

List is in the @GlobalScope
http://docs.godotengine.org/en/3.0/classes/class_@globalscope.html?highlight=%40GlobalScope
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,288 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 :
            (print(OS.get_scancode_string(ev.scancode)))
by (69 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.