_gui_input(event) being called twice for same keystroke on TextEdit node

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Crogon

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.

:bust_in_silhouette: Reply From: kidscancode

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:

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

Crogon | 2021-03-29 22:47

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

fccoelho | 2022-07-24 22:02

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

kidscancode | 2022-07-24 22:04