How do you know if the InputEvent is a Left-Mouse-Click?

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

I followed this tutorial for handling input: http://docs.godotengine.org/en/latest/tutorials/engine/mouse_and_input_coordinates.html?highlight=input

But I only want to do something, if the left mouse button was clicked. How do I check for this?

:bust_in_silhouette: Reply From: batmanasb

I always just use Input.is_action_pressed("nameOfAction") and bind the key or mouse button from the InputMap tab in Project Settings

Great! Thank you :slight_smile:

Yugo | 2016-03-08 21:56

Hi there, I’m struggling with this. I’ve gone over the docs.
I just don’t know what to put in “nameOfAction”.

In the docs I see BUTTON_* as an option. That doesn’t work.
I tried MOUSE_BUTTON but nope. I tried BUTTON_1, BUTTON_2 etc. But no luck.

What am I missing here? Thanks so much

EDIT: Cancel that, I’m a goose. Found it.

Robster | 2017-02-09 00:24

Instead of just saying you found it you could let others know how:

Project > Project Settings > Input Map (tab)

And then the parameters you can use are “ui_left” etc.

ishfwilf | 2019-03-19 20:28

:bust_in_silhouette: Reply From: Hinsbart

Take a look the documentation for InputEventMouseButton.
You’re looking for the button_index property. You can check it like this:

if event.type == InputEvent.MOUSE_BUTTON:
    if event.button_index == BUTTON_LEFT and event.pressed:
        # do something

Of course you can also use InputMap actions for this which is often easier, especially if you want to support multiple input methods (mouse, keyboard, gamepads) for the same gameplay mechanic.

:bust_in_silhouette: Reply From: angstyloop