0 votes

I want to print something if any key is pressed on the keyboard except the enter key. How can I do that? With InputEvent == InputEventKey?

in Engine by (46 points)

1 Answer

+3 votes
Best answer

You almost got it.

Best to detect in the input function.

func _input(event):
    if event is InputEventKey and event.pressed:
        if event.scancode != KEY_ENTER:
            #Do what you gotta do.

If you wanna know what key you are pressing, then that's what that scancode variable in the second if is. However if you print it out as it is it would return an integer.

#Eg: If I pressed A then this would print 64.

That integer is a KeyList enumerator in GlobalScope. Which means you have to compare it against one of those constants to know if it's that key in particular.

#Eg: Now this would print true if I pressed A.
print(event.scancode == KEY_A)

There are more that you can find here under Enums > KeyList.

by (3,891 points)
selected by

Oh and by the way, a question like that would more closely fit Engine category.

Thanks for the help!

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.