Keeping track of left/right mouse buttons?

Is there an easy way to track left and right mouse buttons when they go down/up?

If in mouseDown(…) I use:

That doesn’t help since if right button was pressed down first and after that the left one, without lifting the right one first, I can’t check which button was pressed. Or is the only way to keep track of this myself, by building a bit more complex logic which always tries to compare which buttons were up/down the last time MouseDown/Up was entered?

Is there something that handles this already in JUCE?

You don’t need getCurrentModifiers() in mouseDown(), you can use the mods member in the event.
Unfortunately it still won’t tell you which one just changed the state.
AFAIK you need to store the last modifiers bits yourself in mouseDown and mouseUp.

Also mind the hint in mouseUp:

When used for mouse-up events, this will indicate the state of the mouse buttons just before they were released, so that you can tell which button they let go of.

But that post raised a few more questions:

  • you get a second mouseDown() when adding the other button?
  • What happens if you moved outside the component dragging and press then the other button?
  • Is that sent to the same component that is dragging or to the component currently under the cursor?
    In the later case you could have two components dragging at the same time, so I doubt it

Time for some experiments

I hadn’t tried if I would get a second mouseDown(). I assumed that I would, but it seems that I dont (did a quick test).

If this is a guaranteed behavior, it means that I should be able to do what I need with the system: just check which one of the buttons is down when entering the mouseDown(). Then I don’t need to worry about the second button at all.