classes/class_inputeventmousebutton #250
Replies: 5 comments 7 replies
-
I can not find event.is_double_click() in godot 4.3 |
Beta Was this translation helpful? Give feedback.
-
func _input(event:InputEvent) -> void:
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT and event.double_click:
print("do something") |
Beta Was this translation helpful? Give feedback.
-
Shouldn't we have the position where the mouse was when it was clicked, so that we can use that information? |
Beta Was this translation helpful? Give feedback.
-
Just so everyone knows, code completion does not work for same line conditions.
The editor does NOT show event.button_index to be a valid property. |
Beta Was this translation helpful? Give feedback.
-
The code found on comments above mostly simulated a "mouse up" event. The full implementation that has "mouse up", "mouse down", "mouse clicked" should look like this. using Godot;
public partial class DemoSimpleMouseOperations : Area2D {
bool wasPressedPreviously = false;
bool wasDoubleClickedPreviously = false;
public override void _Ready() {
InputEvent += (viewport, @event, shape_idx) => HandleInput(@event); ;
}
public void HandleInput(InputEvent ipev) {
if (ipev is InputEventMouseButton mb) {
// detect click
if (mb.Pressed) {
GD.Print("mouse down");
}
else if (!mb.Pressed) {
GD.Print("mouse up");
if (wasPressedPreviously) {
GD.Print("mouse clicked");
}
}
// detect double click
if (wasDoubleClickedPreviously && !mb.DoubleClick) {
GD.Print("mouse dbl-clicked");
}
wasPressedPreviously = mb.Pressed;
wasDoubleClickedPreviously = mb.DoubleClick;
}
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
classes/class_inputeventmousebutton
Inherits: InputEventMouse< InputEventWithModifiers< InputEventFromWindow< InputEvent< Resource< RefCounted< Object Represents a mouse button being pressed or released. Description: Stores informati...
https://docs.godotengine.org/en/stable/classes/class_inputeventmousebutton.html
Beta Was this translation helpful? Give feedback.
All reactions