IsActionReleased() with what action?

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

i’m using C# and want to detect if a key or mouse event was just fired.

Using this now:

if (@event.IsActionReleased("ui_accept")) {

but ui_accept doesn’t work, and also tried ‘click’. Is there a list somewhere with actions that are accepted? Is the syntax different from the script to C#?

:bust_in_silhouette: Reply From: juppi

The _Input is called when an input event has happened. You can use it like that:

public override void _Input(InputEvent @event)
{
    if (@event is InputEventMouseButton inputEventMouseButton)
    {
        if (inputEventMouseButton.ButtonIndex == (int)ButtonList.Left)
        {
            GD.Print("Left mouse button has been pressed!");
        }
    }
    else if (@event is InputEventKey inputEventKey)
    {
        if (inputEventKey.Scancode == (uint)KeyList.Escape)
        {
            GD.Print("Escape key has been pressed!");
        }
    }
}

Another way is to use the Input Map. For that you can take the static class Input:

public override void _Process(float delta)
{
    if (Input.IsActionJustPressed("ui_accept"))
    {

    }
}

You can find the Input Map in your Project Settings.