+6 votes

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

in Engine by (10,259 points)

1 Answer

+4 votes
Best answer

Instead of using this code:

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

Use this:

func _input(event):
    if event.is_action_pressed("say_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.

by (10,259 points)
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.
Also if you're parsing input events directly instead of using actions, there are:
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
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.
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 webmaster@godotengine.org with your username.