NSEvent

We discussed NSEvent in terms of mouse events in the previous chapter. Here are some of the properties commonly used when getting information about a keyboard event:

v​a​r​ ​c​h​a​r​a​c​t​e​r​s​:​ ​S​t​r​i​n​g​!​ ​{​ ​g​e​t​ ​}​

Returns the characters created by the event.

v​a​r​ ​A​R​e​p​e​a​t​:​ ​B​o​o​l​ ​{​ ​g​e​t​ ​}​

true if the key event is a repeat caused by the user holding the key down; false if the key event is new.

v​a​r​ ​k​e​y​C​o​d​e​:​ ​U​I​n​t​1​6​ ​{​ ​g​e​t​ ​}​

Returns the code for the keyboard key that caused the 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​ ​}​

Returns an integer bit field indicating the modifier keys in effect ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.