Contents

Mouse, Keyboard, and Trackpad

Handle events related to mouse, keyboard, and trackpad input.

Overview

The NSResponder class defines the responder chain, an ordered list of objects that respond to user events. When the user clicks the mouse button, taps on the trackpad, or presses a key, an event is generated and passed up the responder chain in search of an object that can respond to it. Any object that handles events must inherit from the NSResponder class. The core AppKit classes, NSApplication, NSWindow, and NSView, inherit from NSResponder.

Before a click enters the chain, the system determines where to start: it hit-tests your view hierarchy to find the innermost view underneath the mouse pointer, and that view gets the first chance to respond.

The responder chain receives touch events only from indirect touches on a trackpad, if a view asks for them. It doesn’t receive touch events from direct touches on a Mac with a touch display.

An NSApplication object maintains a list of NSWindow objects — one for each window belonging to the app — and each NSWindow object maintains a hierarchy of NSView objects. Your app uses this view hierarchy both to draw the user interface and to handle events.

An NSWindow object handles window-level events and distributes other events to its views. An NSWindow object also has a delegate allowing you to customize its behavior.

To respond to mouse and touch input consistently across input types, see Handling AppKit gestures.

Topics

Responder Objects

Mouse, Keyboard, and Touch Events

Trackpad

Constants

See Also

User Interactions