Handling Key Events
- any subclass of NSResponder can accept events
key events from NSWindow
- subclass NSWindow, with MyWindow
- in IB, set the window to use the custom class, MyWindow
- override the following method in MyWindow:
- (void)keyDown:(NSEvent *)event { switch ([event keyCode]) { case 121:{ // page down if([event modifierFlags] & NSCommandKeyMask) // only do something if the command key was also pressed // do something break; } } }
key events from a custom view
- make the view the first responder
- there may be a better way to do this, but you can use this:
[view becomeFirstResponder]; or [window makeFirstResponder:view];
- override the keyDown method in the view (see NSWindow above for example)