How to avoid multiple key events when the key is pressed and held ?

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

The following code prints “pressed” repeatedly when the right key is pressed and held without releasing. How to avoid receiving multiple key events when the key is pressed and held ? Thanks

func _input(event):
	if Input.is_action_pressed("ui_right"):
		print("pressed") # printed multiple times, how to avoid this
:bust_in_silhouette: Reply From: kidscancode

You should not be polling the Input singleton in the _input() callback.

Change your code to process the actual event that was triggered:

if event.is_action_pressed("ui_right")

More information:

Wow, i did not expect reply from the same person whose videos i watched on youtube learning godot. Thanks Chris for your youtube channel https://www.youtube.com/channel/UCNaPQ5uLX5iIEHUCLmfAgKg/ . It was very helpful.

bob333 | 2020-06-01 14:08