NSEvent object, or simply an event, contains information about an input action such as a mouse click or a key press. AppKit associates each such user action with a window, reporting the event to the application that created the window. The
NSEvent object contains pertinent information about each event, such as where the cursor was located or which character was typed. As the application receives events, it temporarily places them in a buffer called the event queue. When the application is ready to process an event, it takes one from the queue.
- macOS 10.10+
NSEvent objects can also represent tablet-pointing and tablet-proximity events. A tablet-proximity event is generated when a pointing device enters or leaves the proximity of its tablet; such event objects have a type of
NSTypeProximity or a mouse subtype of
NSTabletProximityEventSubtype. A tablet-pointing event is generated when a pointing device changes state, such as location, pressure, or tilt; such event objects have a type of
NSTypePoint or a mouse subtype of
NSTabletPointEventSubtype. AppKit reports all pure tablet events to responder objects through the
tabletProximity(with:). Mouse events can also contain tablet data (as event subtypes), so you can handle these events by overriding the
NSEvent objects can also represent touch and gesture events. Magnify (pinch), swipe, and rotate masks are supported, as are more generic gesture masks. Using the
touches(matching:in:) method, a view can get all of the touch events associated with a gesture without overriding the individual touch responder methods defined in
Pressure events are supported on devices that support pressure sensitivity. These events are reported as event type
pressure, and invoke the responder method
You can create application event monitors that call handlers in block objects for certain event types that are sent through the
sendEvent(_:) method. You can create a local monitor that will be informed of the events in your application and allow you to modify or cancel them. You can also create a global event monitor that allows you to monitor events in other applications, although you are unable to alter those events. See Monitoring Application Events for more information.