Ignoring key repeats/echos in input handling

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Calinou
:warning: Old Version Published before Godot 3 was released.

How do I ignore the key repeats/echos that occur in input handling, when holding a key?

:bust_in_silhouette: Reply From: Calinou

Instead of using this code:

func _input(event):
    if Input.is_action_pressed("say_hi"):
        print("Hi!")

Use this:

func _input(event):
    if event.is_action_pressed("say_hi"):
        print("Hi!")

Using the input event directly is generally a good idea, as it is less prone to issues that can happen when eg. there also is mouse input in the game.

Let me add an info, that if the subject would be about screen buttons like an in games GUI, you may also use TouchScreenButton and check emulate touchscreen in project settings. TouchScreenButtons do not have a problem of repeats and they work on mobile devices well.

Freeman | 2016-02-22 19:26

Also if you’re parsing input events directly instead of using actions, there are:
event.is_pressed()
and
event.is_echo()

Hinsbart | 2016-02-22 20:58

Input.is_action_pressed() is called polling and can be run anywhere in the code
in fact i think you don’t even need to use _input(event) for event based although it does make it easier for events.
im pretty sure if you do set_process_input(true) in _ready then you can call the Input and InputEvent singletons directly from anywhere

trollworkout | 2016-02-23 08:22