0 votes

I have a TextEdit node, and inside of it I've declared the _gui_input function. Upon typing anything in the text box, the keystroke is put through the function twice. For example:

func _gui_input(event):
    if event is InputEventKey:

will print out "s," and then "s" again, even if I've only hit the S key once. is_echo returns false on the original and duplicate event.

Is this intended behavior? I would imagine the input is only supposed to be registered once, which is what I want.

Godot version 3.2.3
in Engine by (15 points)

1 Answer

+2 votes
Best answer

This is intended behavior because you're generating two key events: press and release. If you only want the keypress event, you need to add that to your condition:

func _gui_input(event):
    if event is InputEventKey and event.pressed:

More information:

by (21,981 points)
selected by

Thank you very much. I don't know how I missed that.

I am doing it like this:

func _input(event):
    if event is InputEventKey and event.pressed:
        if event.scancode == KEY_1:
            update_number(row, col, 1)

and the update_number function is still being called multiple times

Are you sure you don't have this script attached to more than one node?

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 Frequently asked questions and 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 [email protected] with your username.