Introduction

A primary responsibility of an event-driven application is to handle user events—that is, events generated by devices such as mice, keyboards, trackpads, and tablets. For most Cocoa applications, the Application Kit assumes the largest share of this work. It ensures that events generated by the mouse, keyboard, and other devices are routed to the objects best suited to handle them. It also implements dozens of user-interface objects such as controls and text views to respond to events in expected ways—for example, by inserting typed text or sending an action message. But often an application, especially an application with custom NSView, NSWindow, or NSApplication objects, finds that it must handle some events itself.

Cocoa Event Handling Guide explains how to handle events of all types in a Cocoa application. It provides conceptual background for the task-based chapters by describing the Cocoa architecture for dispatching and handling events, and by giving an overview of NSEvent objects, which all event-handling code must deal with. Reading this document will give you a solid foundation for handling events in your Cocoa application.

Organization of This Document

This document includes the following chapters:

The appendix Using Tracking-Area Objects covers the legacy API for mouse tracking and cursor updates. It explains how to set up tracking and cursor rectangles and handle the events that are subsequently generated when users move the mouse cursor into those areas.

See Also

The following documents are conceptually related to Cocoa Event-Handling Guide:

Because view objects often redraw themselves in response to events, it is also recommended that you peruse Cocoa Drawing Guide.

The following sample code projects include illustrative event-handling code: