MouseEvent::getNumberOfClicks() potential issue

Hello,

There seems to be an issue related to MouseEvent::getNumberOfClicks() returns 4 for double-clicks

I just created a new app project via introjucer and add the following code in the main component.

void mouseDown(const juce::MouseEvent& e)
{
  DBG(e.getNumberOfClicks());
}

Now I’m double clicking on the main component, with various timing gaps between each double click, and I get inconsistent results in the console output. Like 1 followed by 3 or by 4.

1
2
1
4 <-- Pb here
1
2
3
4
1
2
1
2
1
2
1
2
1
2
1
3 <-- Pb here

Juce version : 5.4.7
OS : Win 10
VS2019

Thanks !

Can’t see anything wrong with that behaviour.

If you click 3 times in quick succession, then that’s a triple-click. And 4 times, a quadruple click, etc. You seem to be expecting it to group the clicks only into pairs, but that’s not the case - it just counts the number of clicks that happened in quick succession and reports the number.

1 Like

Ok I think I get it, I supposed the intended behavior was to reset a counter when there is no click during enough time, but it’s not that. Thanks for the clarification. :slight_smile:

It’s still tricky however to handle double click properly. Since we can trigger unwanted triple/quadriple clicks with resonnably spaced double click.

It’s like triple/quadriple clicks are most of the time an unwanted feature that is potentially conflicting with the double click detection.

For two double clicks that are close, you have to deal with numberOfClicks patterns like : “1 2 3 4”, “1 2 1 3”, “1 2 1 4”…

It sounds like, to get a “robust” double click detection, there is no trivial condition to apply directly on getNumberOfClicks() without storing any extra state on the component.

Thanks for helping !!

EDIT

I ended up with replacing the double click condition :

if (e.getNumberOfClicks() >= 2)

By

if (mHasDoubleClicked = e.getNumberOfClicks() >= 2 && !mHasDoubleClicked)

Works fine.