On mac osx mouseDrag gets called on mouseDown


For any component any time a mouseDown happens, mouseDrag gets called even if I dont move the mouse? The event position is the same in both mouseDown and mouseDrag. This does not seem to happen on windows. Only on mac os. I am on 10.10.5

MouseDrag called on MouseDown

So what?

You obviously can’t write code that expects not to get mouse drag events!

People have wobbly hands, or track pads that emit pressure changes, or pen tablets that emit torrents of sub-pixel movements, etc etc.


I was just wondering, I just thought it did not make sense that mouseDrag should be called even if the mouse was not dragged.


What makes you think the mouse wasn’t dragged?


You can set a break point in mouseDown and mouseDrag, here is the call stack when mouseDrag is incorrect:

and here is the call stack when mouse drag is correct:

Also it is pretty easy to not drag manually , I tested on windows and mouseDrag was never called.


This is honestly true: one can lift the mouse in the air when pressing the mouse button, that way it’s obvious that no dragging is involved in that click


OK, but to reiterate my original reply: So what?

Robust code can deal with a mouse-drag event coming after a mouse-down. I’ve had a rant about this same thing a couple of times before.

TBH I think it’s doing people a service to have it work the way it does, because if this subtle and not-unexpected behaviour made your program misbehave enough that you posted about it as if it’s a bug, then your app would also have misbehaved in the real world too, when used by people with strange input devices. So the fact that you’re forced to make your code deal with this kind of thing up-front is a bonus, not a bug!


Yes, I know, I have read the other topics about this as well.

I just wanted to add to the discussion a quick, easy and repeatable way to generate clicks that are certainly not accompanied by a mouse move, which may not be so obvious especially if one is used to work only with a trackpad.

I am not implying that I wish this were different, in fact, I see your point about it doing a service to the developer that is forced to consider this case very early.

Also, you should admit that your argument is biased by the fact that you do your development mainly on a Mac.
One that develops only on Win may never think of this because he doesn’t get the drag events on simple clicks.
If then he builds the same project on Mac, all of a sudden he will see these drag on clicks and perceive them as a strange behavior.


This is definitely a bug, mouseDrag should not be called if mouse is not moved after mouse down.

Just need to add the following to make it consistent between platform:

if (e.mouseWasDraggedSinceMouseDown())


An OSX quirk for sure, but it does seem odd that we have to include a test for a mouse drag inside a mouseDrag() method…


I feel I should make something clear to anyone reading this thread who also misunderstands mouseWasDraggedSinceMouseDown():

That function isn’t as simple as “is this a mouse drag event”, it’s a heuristic to help you decide whether the mouse has been held or dragged for a significant enough time/distance for it to be safe to assume that the user is deliberately dragging, rather than just having wobbly hands while they’re actually trying to do a “click”.

mouseDrag() is not smart - it gets called whenever the OS sends a drag event. It doesn’t attempt to filter-out wobbly hands or pen-tablet devices or other continuous input controllers that may produce a stream of events. Like I said in my post above, if you write code that makes assumptions about it not being called during a click then you’re going to have problems.


Got it. No more will I muse over mouseDrag().