NSButton Up/Down Events

Shawn Erickson shawnce at gmail.com
Fri Feb 9 08:46:42 PST 2007


On Feb 9, 2007, at 7:34 AM, Brad Carter wrote:

> I'm new to the list and very new to Cocoa and programming in  
> general.  My only programming experience was Basic about 20 years  
> ago when my father put me in classes.  I have just finished one  
> book on Object C and the other, Cocoa Programming for Mac OS X.
>
> I have an AppleScript Studio app that I'm rewriting in Cocoa.  The  
> app sends a curl command with a URL to a box that does relay  
> closures and that in turn controls the pan/tilt of a video camera.   
> I have the AppleScript set up using mouse down/up events so when  
> the button is pressed and held down the camera pans, when the  
> button is release the panning stops.
>
> I can't figure out how to do this in Cocoa.  I have subclassed  
> NSButton and overridden mouseDown: and mouseUp and display this to  
> NSLog confirming my success.  How do I tell what button was pressed  
> in the mouseDown: method?  I can't find anything in NSEvent that  
> would hint that this info would be passed as an NSEvent.  Here's my  
> code below.

Responder objects (views and controls are such things) get their  
mouseDown: called if the mouse down hit them or hit some responder  
they contain [1]. So the object that got the mouseDown: message was  
the one clicked (aka the one clicked is self).

Review...
<http://developer.apple.com/documentation/Cocoa/Conceptual/ 
EventOverview/HandlingMouseEvents/chapter_5_section_1.html>

It sounds like you need to do something like what is outlined in the  
following...
<http://developer.apple.com/documentation/Cocoa/Conceptual/ 
EventOverview/HandlingMouseEvents/chapter_5_section_4.html>

-Shawn

[1] ...or in some way they are in the responder chain.


More information about the MacOSX-dev mailing list