O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

NSEvent

An event object has all the information about what the user did to trigger the event. When you are dealing with mouse events, you might be interested in the following properties:

v​a​r​ ​l​o​c​a​t​i​o​n​I​n​W​i​n​d​o​w​:​ ​N​S​P​o​i​n​t​ ​{​ ​g​e​t​ ​}​

Returns the location of the mouse event.

v​a​r​ ​m​o​d​i​f​i​e​r​F​l​a​g​s​:​ ​N​S​E​v​e​n​t​M​o​d​i​f​i​e​r​F​l​a​g​s​ ​{​ ​g​e​t​ ​}​

Tells you which modifier keys the user is holding down on the keyboard. This enables the programmer to tell a Control-click from a Shift-click, for example. The code would look like this:

o​v​e​r​r​i​d​e​ ​f​u​n​c​ ​m​o​u​s​e​D​o​w​n​(​t​h​e​E​v​e​n​t​:​ ​N​S​E​v​e​n​t​)​ ​{​ ​ ​ ​l​e​t​ ​f​l​a​g​s​ ​=​ ​t​h​e​E​v​e​n​t​.​m​o​d​i​f​i​e​r​F​l​a​g​s​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required