Chapter 8. Events and Responders
Our Calculator already handles events such as mouseclicks on buttons and menu items, but all this was automatic; we haven’t had to write any specific code to handle these mouse events. In this chapter we’ll learn more about events and the chain of objects that Cocoa uses to respond to events. At the end of the chapter, we’ll see how to “catch” events from the keyboard in our Calculator application. This is the final chapter of the Calculator application.
Events and the NSResponder Chain
There are seven basic kinds of events that Cocoa developers need to be concerned about:
- Mouse events
Generated by pressing, clicking, or moving the mouse
- Keyboard events
Generated by a keypress or release
- Tracking rectangle and cursor-update events
Generated when the cursor crosses the boundary of a predefined rectangular area (tracking rectangle) in a window
- Periodic events
Generated to notify an application that a certain time interval has elapsed
- AppKit-defined events
Generated by the Application Kit when a window is moved, resized, or exposed, or when the application is activated or deactivated
- System-defined events
Generated by the system — for example, when the power is turned off
- NSApplication-defined events
Custom events defined and generated by your application to be inserted into the event queue
Of these, the mouse and keyboard events are usually the most important for developers.
What Is an Event?
A Cocoa event is a message and a corresponding object that the Window ...
Get Building Cocoa Applications: A Step by Step 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.