Reputation: 2242
I have a custom NSView and I want the user to be able to click and drag inside it. NSView of course will receive the mouse drag events and respond appropriately. While the mouse is being dragged I want to make sure that the mouse cursor doesn't move.
I could probably hide the cursor and make it reappear at the same location once the user stops dragging but is there a better way of doing this?
Upvotes: 3
Views: 796
Reputation: 1704
Nicer solution – use the CGAssociateMouseAndMouseCursorPosition
function to enable/disable the cursor from moving.
Your way of just jumping the mouse back can sometimes appear to the user as the mouse moving a little bit, and then jumping back really quickly.
Upvotes: 2
Reputation: 2242
Ended up observing kCGEventLeftMouseDragged events and then calling CGWarpMouseCursorPosition to reset the mouse position. The cursor stays put the whole time I'm dragging.
Upvotes: 1