0 votes

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
asked May 31 in Engine by bob333 (28 points)

1 Answer

+1 vote
Best answer

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:
https://docs.godotengine.org/en/3.2/tutorials/inputs/input_examples.html

answered May 31 by kidscancode (16,966 points)
selected Jun 1 by bob333

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.

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.