Contents

Introduction

Introduces event mechanisms and the types of events in Cocoa and describes how to handle events of each type.

Organization of This Document

This document includes the following chapters:

Event Architecture describes how events enter a Cocoa application, how they are dispatched to view objects, and how they are handled, sometimes after traveling up a chain of responder objects.

Event Objects and Types examines the Cocoa objects that represent events and surveys the types of events a Cocoa application can receive.

Event Handling Basics presents the fundamental tasks in event-handling code regardless of event type.

Handling Mouse Events describes how you can handle events arising from the user clicking or dragging the mouse.

Handling Key Events describes how you can handle events resulting from the user pressing keys on a keyboard.

Using Tracking-Area Objects explains how to use NSTrackingArea objects to manage mouse tracking and cursor updates within regions of views.

Handling Tablet Events describes how to handle events generated by moving and manipulating a stylus over a tablet device.

Text System Defaults and Key Bindings discusses the mechanism for binding key combinations to action messages and describes various defaults that can be applied to Cocoa’s text system.

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 :

View Programming Guide

Text Input Management

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:

BoingX —mouse dragging, key events

CIAnnotation —mouse clicks, mouse dragging

Cocoa OpenGL —mouse clicks, key events

Color Sampler —mouse clicks, mouse dragging

Cropped Image —mouse clicks, mouse dragging

DragItemAround —mouse clicks, mouse dragging, keyboard actions

FunkyOverlayWindow —mouse tracking

ImageMapExample —mouse dragging, mouse tracking

People —key events

CircleView —mouse clicks, mouse dragging

ClockControl —responder related, keyboard actions

DotView —mouse clicks

Rulers —mouse dragging

SimpleStickies —mouse clicks, mouse dragging

Next

Copyright © 2016 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2016-09-13