0 votes

Hello. I can't figure out how to detect both click and doubleclick on the same control separately. Is it ever possible?

Simple test

func _on_gui_input(ev):
    if ev is InputEventMouseButton:
        printt(ev.pressed, ev.doubleclick)

shows that:

click is 2 events

mouse_down = pressed and not doubleclick
mouse_up = not pressed and not doubleclick

doubleclick is 4 events

mouse_down = pressed and not doubleclick
mouse_up = not pressed and not doubleclick
mouse_down = pressed and doubleclick
mouse_up = not pressed and not doubleclick

First 2 events are exactly the same as click and click will be fired too even if I doubleclicked only.

in Engine by (12 points)

1 Answer

0 votes

Well just check if it was doubleClicked before you check if it was just clicked:

func _on_gui_input(ev):
    if ev is InputEventMouseButton:
        if ev.doubleclick:
            pass
            #do on double click
        elif ev.pressed:
            pass
            #do on simple click
        printt(ev.pressed, ev.doubleclick)
by (260 points)

This would be fine if it worked.

extends Area2D

func _on_Area2D_input_event(viewport, event, shape_idx):
    if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
        if event.doubleclick:
            printt("doubleclick")
        elif event.pressed:
            printt("pressed")

And the output is

pressed
doubleclick

This issue has been haunting me for quite a while, is it a bug in Godot?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.