Chapter 15. Images and Mouse Events

In Chapter 14, you drew lines connecting random points. A more interesting application would have been to write some sort of a drawing application. To write this sort of application, you will need to be able to get and handle mouse events.

NSResponder

NSView inherits from NSResponder. All of the event-handling methods are declared in NSResponder. We will discuss keyboard events in Chapter 16. For now, we are interested just in mouse events. NSResponder declares these methods:

- (void)mouseDown:(NSEvent *)theEvent;
- (void)rightMouseDown:(NSEvent *)theEvent;
- (void)otherMouseDown:(NSEvent *)theEvent;
- (void)mouseUp:(NSEvent *)theEvent;
- (void)rightMouseUp:(NSEvent *)theEvent;
- (void)otherMouseUp:(NSEvent *)theEvent; ...

Get COCOA PROGRAMMING FOR MAC OS X SECOND EDITION 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.