Mouse double click

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

Hi,
how to simulate a double click mouse button?
Needs a timer?
Thanks
-j

:bust_in_silhouette: Reply From: volzhs
func _ready():
	get_node("Button").connect("input_event", self, "on_input")

func on_input(ev):
	if ev.type==InputEvent.MOUSE_BUTTON and ev.is_pressed() and ev.doubleclick:
		print("double clicked !")

Thanks,
this works for all mouse buttons.
If I want work on a specific button? For example only for left button?
-j

jospic | 2016-06-29 17:19

then add ev.button_index==1 too.

volzhs | 2016-06-29 17:23

Thanks. It Works!
Is there anyway to simulate long press click?
Thanks a lot.
-j

jospic | 2016-06-30 07:58

:bust_in_silhouette: Reply From: genete

You have to warp the InputEvent and then check if it is a InputEventMouseButton. Then you can test if it is a double click:

func _ready():
	set_process_input(true)
   
func _input(event):
	if event.type==InputEvent.MOUSE_TYPE
		if event.doubleclick:
			print("double click pressed")

Read this too.