As I let go of the key?

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

Hello,
I know that one can press if (Input.is_action_pressed("******")): the keys.

But how do I do this when I do not press the key?

:bust_in_silhouette: Reply From: YeOldeDM

You can always check if not Input.is_action_pressed("action"), but that is probably not quite what you’re looking for. From the sounds of it, you want a single ping on the frame that you release the action.

If you’re checking input with set_process_input(true) and _input(event), you can check if event.is_action_released("action")

Or, you can use a global var in your script to hold a flag which is set true/false based on your input, then checks the difference between the two before setting. If the flag is true (we’ve been holding down the action) but input is false on this frame, we know we’ve just released the action.

var action_held = false

func _fixed_process(delta):
    var ACT = Input.is_action_pressed("action")
    if not action_held and ACT:
        action_just_pressed()
    if action_held and not ACT:
        action_just_released()

    action_held = ACT

From the unreleased 2.2 and forward this is builtin Input — Godot Engine (latest) documentation in English

This of course currently means you would have to built godot from source - but as 3.0 is coming soon it’s still worth to make a note of this.

guppy42 | 2017-06-06 08:01