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?

asked May 18, 2018 in Gossip by aagoldberg (46 points)

1 Answer

+2 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.

answered May 18, 2018 by SIsilicon (3,796 points)
selected May 18, 2018 by aagoldberg

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.