Godot engine C# event BUTTON_RIGHT?

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

Anyone know how to do this in Godot c #.
I want to detect the mouse input as follows, but I can’t find the solution.

Alguien sabe hacer esto en Godot c#.
osea quiero detectar el input del mouse de la siguiente forma,pero no puedo encontrar la solución.

In Godot Gdscript working
func _input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_RIGHT and event.pressed:
pass


In Godot c# no working

public override void _Input(InputEvent @event)
{
if(@event is InputEventMouseButton evento)

         if(evento.Pressed && evento.ButtonIndex == BUTTON_RIGHT)
         {
        
         }

}

:bust_in_silhouette: Reply From: Zylann

In C#, global constants are stored in an enum.
Try with ButtonList.Right: https://godotsharp.net/api/3.2.0/Godot.ButtonList/

I didn’t know that page with the Godot c # API, thanks for sharing it.
Now the problem is that the comparison cannot be made.
if (“event.ButtonIndex == ButtonList.Right”)
Also thank you very much.

regards

Ariel Gimenez | 2020-03-10 10:51

Yeah C# is picky, and the Godot API isn’t very idiomatic to C#. So you have to cast it to int:

if (event.ButtonIndex == (int)ButtonList.Right)

Zylann | 2020-03-10 13:46

Thank you very much, now it worked.

Ariel Gimenez | 2020-03-10 13:52