An object that contains information about an input action such as a mouse click or a key press.
SDK
- macOS 10.0+
Framework
- App
Kit
Declaration
class NSEvent : NSObject
Overview
AppKit associates each user action, such as a mouse click, with a window and reports 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.
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 NSType
or a mouse subtype of NSTablet
. 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 NSType
or a mouse subtype of NSTablet
. AppKit reports all pure tablet events to responder objects through the NSResponder
methods tablet
and tablet
. Mouse events can also contain tablet data (as event subtypes), so you can handle these events by overriding the NSResponder
methods mouse
, mouse
, and mouse
.
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:
method, a view can get all of the touch events associated with a gesture without overriding the individual touch responder methods defined in NSResponder
.
Pressure events are supported on devices that support pressure sensitivity. These events are reported as event type NSEvent
, and invoke the responder method pressure
in NSResponder
or pressure
in NSGesture
.
You can create application event monitors that call handlers in block objects for certain event types that are sent through the NSApplication
send
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.