How can I find out if a button was pressed with the right or left mouse button?

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

How can I find out if a button was pressed with the right or left mouse button?

This didn’t work:

func _on_Button_pressed():
    if Input.is_key_pressed(BUTTON_LEFT):
        # left button clicked
    elif Input.is_key_pressed(BUTTON_RIGHT):
         # right button clicked
:bust_in_silhouette: Reply From: njamster

Connect the gui_input-signal:

func _on_Button_gui_input(event):
    if event is InputEventMouseButton and event.pressed:
        match event.button_index:
            BUTTON_LEFT:
                # left button clicked
            BUTTON_RIGHT:
                # right button clicked

Thank you very much!

MaxEl777 | 2020-04-20 11:32

This worked perfectly for me, just what I wanted! Thanks!

Andrew2022 | 2022-10-13 20:38

For those working with Godot 4, use MOUSE_BUTTON_LEFT and MOUSE_BUTTON_RIGHT instead

MoltenCoffee | 2023-06-19 18:19