<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSEvent",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSEvent"
  },
  "title" : "NSEvent"
}
-->

# NSEvent

An object that contains information about an input action, such as a mouse click or a key press.

```
class NSEvent
```

## Overview

AppKit reports events that occur in a window to the app that created the window. Events include mouse clicks, key presses, and other types of input to the system. An [`NSEvent`](/documentation/AppKit/NSEvent) object contains pertinent information about each event, such as the event type and when the event occurred. The event type defines what other information is available in the event object. For example, a keyboard event contains information about the pressed keys.

Although you can create [`NSEvent`](/documentation/AppKit/NSEvent) objects directly, you typically don’t. The system generates them automatically in response to input from the mouse, keyboard, trackpad, or other peripherals such as connected tablets. It enqueues those events in its event queue, and dequeues them when it’s ready to process them. The system delivers events to the most relevant [`NSResponder`](/documentation/AppKit/NSResponder) object, which might be the first responder or the object where the event occurred. For example, the system delivers mouse-click events to the view that contains the event location.

To handle events, add support to your app’s [`NSResponder`](/documentation/AppKit/NSResponder) objects. You can also use gesture recognizers to handle some events for you and execute your app’s code at appropriate times. For more information, see the [`NSResponder`](/documentation/AppKit/NSResponder) reference.

You can also monitor the events your app receives and modify or cancel some events as needed. Install a local monitor using the [`addLocalMonitorForEvents(matching:handler:)`](/documentation/AppKit/NSEvent/addLocalMonitorForEvents(matching:handler:)) method to detect specific types of events and take action when your app receives them. Install a global monitor using the [`addGlobalMonitorForEvents(matching:handler:)`](/documentation/AppKit/NSEvent/addGlobalMonitorForEvents(matching:handler:)) method to monitor events systemwide, although without the ability to modify them.

## Topics

### Creating an event object

[`keyEvent(with:location:modifierFlags:timestamp:windowNumber:context:characters:charactersIgnoringModifiers:isARepeat:keyCode:)`](/documentation/AppKit/NSEvent/keyEvent(with:location:modifierFlags:timestamp:windowNumber:context:characters:charactersIgnoringModifiers:isARepeat:keyCode:))

Creates and returns a new event object that describes a key event.

[`mouseEvent(with:location:modifierFlags:timestamp:windowNumber:context:eventNumber:clickCount:pressure:)`](/documentation/AppKit/NSEvent/mouseEvent(with:location:modifierFlags:timestamp:windowNumber:context:eventNumber:clickCount:pressure:))

Creates and returns a new event object that describes a mouse-down, -up, -moved, or -dragged event.

[`enterExitEvent(with:location:modifierFlags:timestamp:windowNumber:context:eventNumber:trackingNumber:userData:)`](/documentation/AppKit/NSEvent/enterExitEvent(with:location:modifierFlags:timestamp:windowNumber:context:eventNumber:trackingNumber:userData:))

Creates and returns a new event object that describes a tracking-rectangle or cursor-update event.

[`otherEvent(with:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:)`](/documentation/AppKit/NSEvent/otherEvent(with:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:))

Creates and returns a new event object that describes a custom event.

[`init(eventRef:)`](/documentation/AppKit/NSEvent/init(eventRef:))

Creates and returns a new event object for a Carbon event.

[`init(cgEvent:)`](/documentation/AppKit/NSEvent/init(cgEvent:)-4igjn)

Creates and returns an event object for a Core Graphics event.

### Getting the event type

[`type`](/documentation/AppKit/NSEvent/type)

The event’s type.

[`NSEvent.EventType`](/documentation/AppKit/NSEvent/EventType)

Constants for the types of events that responder objects can handle.

[`NSEvent.EventTypeMask`](/documentation/AppKit/NSEvent/EventTypeMask)

Constants that you use to filter out specific event types from the stream of incoming events.

[`subtype`](/documentation/AppKit/NSEvent/subtype)

The event’s subtype.

[`NSEvent.EventSubtype`](/documentation/AppKit/NSEvent/EventSubtype)

Subtypes for various types of events.

### Getting general event information

[`locationInWindow`](/documentation/AppKit/NSEvent/locationInWindow)

The event location in the base coordinate system of the associated window.

[`timestamp`](/documentation/AppKit/NSEvent/timestamp)

The time when the event occurred in seconds since system startup.

[`window`](/documentation/AppKit/NSEvent/window)

The window object associated with the event.

[`windowNumber`](/documentation/AppKit/NSEvent/windowNumber)

The identifier for the window device associated with the event.

[`eventRef`](/documentation/AppKit/NSEvent/eventRef)

An opaque Carbon type associated with this event.

[`cgEvent`](/documentation/AppKit/NSEvent/cgEvent)

The Core Graphics event object corresponding to this event.

[`foreverDuration`](/documentation/AppKit/NSEvent/foreverDuration)

The longest time duration possible.

### Getting modifier flags

[`modifierFlags`](/documentation/AppKit/NSEvent/modifierFlags-swift.property)

An integer bit field that indicates the pressed modifier keys.

[`NSEvent.ModifierFlags`](/documentation/AppKit/NSEvent/ModifierFlags-swift.struct)

Flags that represent key states in an event object.

[`modifierFlags`](/documentation/AppKit/NSEvent/modifierFlags-swift.type.property)

The currently pressed modifier keys.

### Getting key event information

[`characters`](/documentation/AppKit/NSEvent/characters)

The characters associated with a key-up or key-down event.

[`charactersIgnoringModifiers`](/documentation/AppKit/NSEvent/charactersIgnoringModifiers)

The characters generated by a key event as if no modifier key (except for Shift) applies.

[`keyCode`](/documentation/AppKit/NSEvent/keyCode)

The virtual code for the key associated with the event.

[`characters(byApplyingModifiers:)`](/documentation/AppKit/NSEvent/characters(byApplyingModifiers:))

Returns the new characters that result if you apply the specified modifier keys to the event.

[`keyRepeatDelay`](/documentation/AppKit/NSEvent/keyRepeatDelay)

The number of seconds someone must hold down a key before the first key repeat event occurs.

[`keyRepeatInterval`](/documentation/AppKit/NSEvent/keyRepeatInterval)

The number of seconds someone must hold down a key to generate key-repeat events after the initial delay.

[`specialKey`](/documentation/AppKit/NSEvent/specialKey-swift.property)

The code associated with a function key or other special key.

[Function-Key Unicode Values](/documentation/AppKit/function-key-unicode-values)

Constants for reserved keyboard function keys that correspond to unicode characters.

[`NSEvent.SpecialKey`](/documentation/AppKit/NSEvent/SpecialKey-swift.struct)

Constants for reserved function keys on the keyboard.

[`isARepeat`](/documentation/AppKit/NSEvent/isARepeat)

A Boolean value that indicates whether the key event is a repeat.

### Getting mouse event information

[`pressedMouseButtons`](/documentation/AppKit/NSEvent/pressedMouseButtons)

The indices of the currently pressed mouse buttons.

[`doubleClickInterval`](/documentation/AppKit/NSEvent/doubleClickInterval)

The maximum number of seconds in which a second mouse click must occur for an event to be a double-click event.

[`mouseLocation`](/documentation/AppKit/NSEvent/mouseLocation)

Reports the current mouse position in screen coordinates.

[`buttonNumber`](/documentation/AppKit/NSEvent/buttonNumber)

The button number for a mouse event.

[`clickCount`](/documentation/AppKit/NSEvent/clickCount)

The number of mouse clicks associated with a mouse-down or mouse-up event.

[`associatedEventsMask`](/documentation/AppKit/NSEvent/associatedEventsMask)

The associated events mask of a mouse event.

### Getting scroll wheel and flick events

[`deltaX`](/documentation/AppKit/NSEvent/deltaX)

The x-coordinate change for scroll wheel, mouse-move, mouse-drag, and swipe events.

[`deltaY`](/documentation/AppKit/NSEvent/deltaY)

The y-coordinate change for scroll wheel, mouse-move, mouse-drag, and swipe events.

[`deltaZ`](/documentation/AppKit/NSEvent/deltaZ)

The z-coordinate change for a scroll wheel, mouse-move, or mouse-drag event.

[`hasPreciseScrollingDeltas`](/documentation/AppKit/NSEvent/hasPreciseScrollingDeltas)

A Boolean value that indicates whether precise scrolling deltas are available.

[`scrollingDeltaX`](/documentation/AppKit/NSEvent/scrollingDeltaX)

The scroll wheel’s horizontal delta.

[`scrollingDeltaY`](/documentation/AppKit/NSEvent/scrollingDeltaY)

The scroll wheel’s vertical delta.

[`momentumPhase`](/documentation/AppKit/NSEvent/momentumPhase)

The momentum phase for a scroll or flick gesture.

[`isDirectionInvertedFromDevice`](/documentation/AppKit/NSEvent/isDirectionInvertedFromDevice)

A Boolean value that indicates whether the user has changed the device inversion.

### Configuring swipe event behaviors

[`isSwipeTrackingFromScrollEventsEnabled`](/documentation/AppKit/NSEvent/isSwipeTrackingFromScrollEventsEnabled)

A Boolean value that indicates whether to track fluid swipe gestures using scroll events.

[`trackSwipeEvent(options:dampenAmountThresholdMin:max:usingHandler:)`](/documentation/AppKit/NSEvent/trackSwipeEvent(options:dampenAmountThresholdMin:max:usingHandler:))

Allows tracking and user interface feedback of scroll wheel events.

[`NSEvent.SwipeTrackingOptions`](/documentation/AppKit/NSEvent/SwipeTrackingOptions)

Constants that specify swipe-tracking options.

### Getting gesture and touch information

[`phase`](/documentation/AppKit/NSEvent/phase-swift.property)

The phase of a gesture event, such as a magnify, scroll, or pressure change.

[`NSEvent.Phase`](/documentation/AppKit/NSEvent/Phase-swift.struct)

Constants that represent the possible phases during an event phase.

[`magnification`](/documentation/AppKit/NSEvent/magnification)

The amount of change to add to a magnification gesture.

[`touches(matching:in:)`](/documentation/AppKit/NSEvent/touches(matching:in:))

Returns the touch objects associated with the specified phase.

[`allTouches()`](/documentation/AppKit/NSEvent/allTouches())

Returns all touch objects associated with the event.

[`touches(for:)`](/documentation/AppKit/NSEvent/touches(for:))

Returns the touch objects from the event that belong to the specified view.

[`coalescedTouches(for:)`](/documentation/AppKit/NSEvent/coalescedTouches(for:))

Returns all of the touch objects associated with the specified main touch.

[`isMouseCoalescingEnabled`](/documentation/AppKit/NSEvent/isMouseCoalescingEnabled)

A Boolean value that indicates whether the system coalesces mouse movement events.

[`NSEvent.GestureAxis`](/documentation/AppKit/NSEvent/GestureAxis)

Constants that specify the direction of travel for a gesture.

### Getting pressure information

[`pressure`](/documentation/AppKit/NSEvent/pressure)

A normalized value that indicates the degree of pressure applied to an appropriate input device.

[`stage`](/documentation/AppKit/NSEvent/stage)

A value that indicates the stage of a pressure gesture event.

[`stageTransition`](/documentation/AppKit/NSEvent/stageTransition)

The transition value for the stage of a pressure gesture event.

[`pressureBehavior`](/documentation/AppKit/NSEvent/pressureBehavior-swift.property)

The behavior and progression for a pressure event.

[`NSEvent.PressureBehavior`](/documentation/AppKit/NSEvent/PressureBehavior-swift.enum)

These constants describe the behavior and progression of a pressure gesture.

### Getting tablet proximity information

[`capabilityMask`](/documentation/AppKit/NSEvent/capabilityMask)

A mask that indicates the capabilities of the tablet device that generated this event.

[`deviceID`](/documentation/AppKit/NSEvent/deviceID)

A special identifier the system matches against tablet-pointer and tablet-proximity events.

[`isEnteringProximity`](/documentation/AppKit/NSEvent/isEnteringProximity)

A Boolean value that indicates whether a pointing device is entering or leaving the proximity of its tablet.

[`pointingDeviceID`](/documentation/AppKit/NSEvent/pointingDeviceID)

The index of the pointing device currently in proximity with the tablet.

[`pointingDeviceSerialNumber`](/documentation/AppKit/NSEvent/pointingDeviceSerialNumber)

The vendor-assigned serial number of a pointing device.

[`pointingDeviceType`](/documentation/AppKit/NSEvent/pointingDeviceType-swift.property)

The kind of pointing device associated with this event.

[`NSEvent.PointingDeviceType`](/documentation/AppKit/NSEvent/PointingDeviceType-swift.enum)

The pointing-device types for tablet-proximity events or mouse events with a proximity event subtype.

[`systemTabletID`](/documentation/AppKit/NSEvent/systemTabletID)

The index of the tablet device connected to the system.

[`tabletID`](/documentation/AppKit/NSEvent/tabletID)

The USB model identifier of the tablet device associated with this event.

[`uniqueID`](/documentation/AppKit/NSEvent/uniqueID)

The unique identifier of the pointing device that generated this event.

[`vendorID`](/documentation/AppKit/NSEvent/vendorID)

The vendor identifier of the tablet associated with the event.

[`vendorPointingDeviceType`](/documentation/AppKit/NSEvent/vendorPointingDeviceType)

A coded bit field whose set bits indicate the type of pointing device (within a vendor selection) associated with the event.

### Getting tablet pointing information

[`absoluteX`](/documentation/AppKit/NSEvent/absoluteX)

The absolute x coordinate of a pointing device on its tablet at full tablet resolution.

[`absoluteY`](/documentation/AppKit/NSEvent/absoluteY)

The absolute y coordinate of a pointing device on its tablet at full tablet resolution.

[`absoluteZ`](/documentation/AppKit/NSEvent/absoluteZ)

The absolute z coordinate of pointing device on its tablet at full tablet resolution.

[`buttonMask`](/documentation/AppKit/NSEvent/buttonMask-swift.property)

A bit mask identifying the buttons pressed for a tablet event.

[`NSEvent.ButtonMask`](/documentation/AppKit/NSEvent/ButtonMask-swift.struct)

Constants you use to identify the activated tablet buttons in an event.

[`rotation`](/documentation/AppKit/NSEvent/rotation)

The rotation in degrees of the tablet pointing device associated with this event.

[`tangentialPressure`](/documentation/AppKit/NSEvent/tangentialPressure)

The tangential pressure on the device that generated this event.

[`tilt`](/documentation/AppKit/NSEvent/tilt)

The scaled tilt values of the pointing device that generated this event.

[`vendorDefined`](/documentation/AppKit/NSEvent/vendorDefined)

An array of three vendor-defined number objects associated with a pointing-type event.

### Getting tracking area information

[`eventNumber`](/documentation/AppKit/NSEvent/eventNumber)

The counter value of the latest mouse or tracking-rectangle event object.

[`trackingNumber`](/documentation/AppKit/NSEvent/trackingNumber)

The identifier of a mouse-tracking event.

[`trackingArea`](/documentation/AppKit/NSEvent/trackingArea)

The tracking area for the event.

[`userData`](/documentation/AppKit/NSEvent/userData)

The data associated with a mouse-tracking event.

### Getting custom event information

[`data1`](/documentation/AppKit/NSEvent/data1)

Additional data associated with this event.

[`data2`](/documentation/AppKit/NSEvent/data2)

Additional data associated with this event.

### Requesting and stopping periodic events

[`startPeriodicEvents(afterDelay:withPeriod:)`](/documentation/AppKit/NSEvent/startPeriodicEvents(afterDelay:withPeriod:))

Begins generating periodic events for the current thread.

[`stopPeriodicEvents()`](/documentation/AppKit/NSEvent/stopPeriodicEvents())

Stops generating periodic events for the current thread and discards any periodic events remaining in the queue.

### Monitoring app events

[`addGlobalMonitorForEvents(matching:handler:)`](/documentation/AppKit/NSEvent/addGlobalMonitorForEvents(matching:handler:))

Installs an event monitor that receives copies of events the system posts to other applications.

[`addLocalMonitorForEvents(matching:handler:)`](/documentation/AppKit/NSEvent/addLocalMonitorForEvents(matching:handler:))

Installs an event monitor that receives copies of events the system posts to this app prior to their dispatch.

[`removeMonitor(_:)`](/documentation/AppKit/NSEvent/removeMonitor(_:))

Removes the specified event monitor.

### Converting a mouse event’s position into a SpriteKit node’s coordinate space

[`location(in:)`](/documentation/AppKit/NSEvent/location(in:))

Returns the location of the receiver in the coordinate system of the given node.

### Deprecated

[`context`](/documentation/AppKit/NSEvent/context)

The display graphics context for this event.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)