How to distinguish mouse clicked vs. mouse pressed

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

I have a collisionshape2d. When the user clicks on it they will hold it and drag it around until they release the button, but they’ll only drag it along one axis. This means that the cursor isn’t always over the object being dragged, which also means you can roll over another similarly draggable object with the mouse button pressed. Does godot give me a way to know an input event on a shape is a change from released to pressed?

:bust_in_silhouette: Reply From: Dlean Jeans

Yes, InputEventMouseButton has a pressed property:

func _input(event):
	if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
		pressed = event.pressed

What does that do if you rolled over the collisionshape with the mouse held down? Does that not emit a new event? Maybe i’m fussing over a non-issue.

dwpasquinelli | 2019-01-06 06:04

Do some tests, I think that your pickable CollisionObjects may get a pressed event, but also an entered signal, so you may need to keep track of entered before accepting pressed.

Also use input_event, not _input on CollisionObjects (unless you want to process general input).

eons | 2019-01-06 18:04

I think i understand now. InputEventMouseButton only fires when the mouse buttons change states, so the problem i thought i was going to have won’t happen. If i wanted to catch rollovers with a mouse button pressed i would need to catch the InputEventMouseMotion and poll the state of the buttons there. Thanks all.

dwpasquinelli | 2019-01-06 19:34