Distinguish double click from single click

I want to trigger different actions for single click (selecting the component) and double click (call an editor).

To achieve this I’ve added addMouseListener( this, true); to the constructor of the component.

But in ::mouseDown() I will of course get two mouseDowns for a ::mouseDoubleClick(), but there is no mouseSingleClick(). What’s the way to go to differentiate a single click from a double click?

For now I came up with this:

void GUIPlayModePatchComponent::mouseDoubleClick(const MouseEvent& event) {
    std::cout << "Double-Click\n";

    stopTimer();  // Cancle pending single click
    std::cout << "Single click canceled\n";

void GUIPlayModePatchComponent::mouseDown(const MouseEvent& event) {
    std::cout << "Starting single click detection!\n";

void GUIPlayModePatchComponent::timerCallback() {
    // Distinguish DoubleClick from single
    // When this routine is reached we had a single click
    std::cout << "That was a confirmed single-click\n";

Is that the way to go?



You should set your timer using MouseEvent::getDoubleClickTimeout(). Your system will work, however it will feel a bit odd to the user since there will be a noticeable delay before the item gets selected.

The standard way to handle things is to always perform the single click action and then perform the double click action if it happens. Will your user find it odd if the editor opens but the selection doesn’t move?

1 Like


Helpful hints thank you!