views:

17

answers:

2

I'm looking for the right way to handle "mouse held down in one spot" events in my NSView subclass.

I am familiar with Cocoa's mouseDragged: event, but it is only triggered when the mouse moves. If the mouse stays in the same position, no drag event is triggered. Similarly, mouseDown: is only fired when the button is first pressed. My view needs to perform an action as long as the mouse is held down in a particular region.

What is the proper way to do this kind of thing?

+2  A: 

Can you start performing the action when you receive a mouseDown: event, and stop when you receive mouseUp: (or mouseDragged:, if you want to stop then, too)?

mipadi
+1 That would certainly work. I guess I'm just surprised that there isn't a built-in Event or method for handling that kind of thing. I was expecting an event something like `mouseStillDown:`
e.James
+1  A: 

I'm not sure exactly what you're trying to accomplish, but if you want an action to be repeated at set time intervals after the mouseDown:, you could set a recurring NSTimer in the mouseDown: method that gets cancelled as soon as there is a mouseDragged: or mouseUp: event.

Dan Messing

related questions