---
title: NSEvent
framework: appkit
role: symbol
role_heading: Class
path: appkit/nsevent
---

# NSEvent

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

## Declaration

```swift
class NSEvent
```

## Overview

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 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 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 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 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 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:) method to detect specific types of events and take action when your app receives them. Install a global monitor using the 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:)](appkit/nsevent/keyevent(with:location:modifierflags:timestamp:windownumber:context:characters:charactersignoringmodifiers:isarepeat:keycode:).md)
- [mouseEvent(with:location:modifierFlags:timestamp:windowNumber:context:eventNumber:clickCount:pressure:)](appkit/nsevent/mouseevent(with:location:modifierflags:timestamp:windownumber:context:eventnumber:clickcount:pressure:).md)
- [enterExitEvent(with:location:modifierFlags:timestamp:windowNumber:context:eventNumber:trackingNumber:userData:)](appkit/nsevent/enterexitevent(with:location:modifierflags:timestamp:windownumber:context:eventnumber:trackingnumber:userdata:).md)
- [otherEvent(with:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:)](appkit/nsevent/otherevent(with:location:modifierflags:timestamp:windownumber:context:subtype:data1:data2:).md)
- [init(eventRef:)](appkit/nsevent/init(eventref:).md)
- [init(cgEvent:)](appkit/nsevent/init(cgevent:)-4igjn.md)

### Getting the event type

- [type](appkit/nsevent/type.md)
- [NSEvent.EventType](appkit/nsevent/eventtype.md)
- [NSEvent.EventTypeMask](appkit/nsevent/eventtypemask.md)
- [subtype](appkit/nsevent/subtype.md)
- [NSEvent.EventSubtype](appkit/nsevent/eventsubtype.md)

### Getting general event information

- [locationInWindow](appkit/nsevent/locationinwindow.md)
- [timestamp](appkit/nsevent/timestamp.md)
- [window](appkit/nsevent/window.md)
- [windowNumber](appkit/nsevent/windownumber.md)
- [eventRef](appkit/nsevent/eventref.md)
- [cgEvent](appkit/nsevent/cgevent.md)
- [foreverDuration](appkit/nsevent/foreverduration.md)

### Getting modifier flags

- [modifierFlags](appkit/nsevent/modifierflags-swift.property.md)
- [NSEvent.ModifierFlags](appkit/nsevent/modifierflags-swift.struct.md)
- [modifierFlags](appkit/nsevent/modifierflags-swift.type.property.md)

### Getting key event information

- [characters](appkit/nsevent/characters.md)
- [charactersIgnoringModifiers](appkit/nsevent/charactersignoringmodifiers.md)
- [keyCode](appkit/nsevent/keycode.md)
- [characters(byApplyingModifiers:)](appkit/nsevent/characters(byapplyingmodifiers:).md)
- [keyRepeatDelay](appkit/nsevent/keyrepeatdelay.md)
- [keyRepeatInterval](appkit/nsevent/keyrepeatinterval.md)
- [specialKey](appkit/nsevent/specialkey-swift.property.md)
- [Function-Key Unicode Values](appkit/function-key-unicode-values.md)
- [NSEvent.SpecialKey](appkit/nsevent/specialkey-swift.struct.md)
- [isARepeat](appkit/nsevent/isarepeat.md)

### Getting mouse event information

- [pressedMouseButtons](appkit/nsevent/pressedmousebuttons.md)
- [doubleClickInterval](appkit/nsevent/doubleclickinterval.md)
- [mouseLocation](appkit/nsevent/mouselocation.md)
- [buttonNumber](appkit/nsevent/buttonnumber.md)
- [clickCount](appkit/nsevent/clickcount.md)
- [associatedEventsMask](appkit/nsevent/associatedeventsmask.md)

### Getting scroll wheel and flick events

- [deltaX](appkit/nsevent/deltax.md)
- [deltaY](appkit/nsevent/deltay.md)
- [deltaZ](appkit/nsevent/deltaz.md)
- [hasPreciseScrollingDeltas](appkit/nsevent/hasprecisescrollingdeltas.md)
- [scrollingDeltaX](appkit/nsevent/scrollingdeltax.md)
- [scrollingDeltaY](appkit/nsevent/scrollingdeltay.md)
- [momentumPhase](appkit/nsevent/momentumphase.md)
- [isDirectionInvertedFromDevice](appkit/nsevent/isdirectioninvertedfromdevice.md)

### Configuring swipe event behaviors

- [isSwipeTrackingFromScrollEventsEnabled](appkit/nsevent/isswipetrackingfromscrolleventsenabled.md)
- [trackSwipeEvent(options:dampenAmountThresholdMin:max:usingHandler:)](appkit/nsevent/trackswipeevent(options:dampenamountthresholdmin:max:usinghandler:).md)
- [NSEvent.SwipeTrackingOptions](appkit/nsevent/swipetrackingoptions.md)

### Getting gesture and touch information

- [phase](appkit/nsevent/phase-swift.property.md)
- [NSEvent.Phase](appkit/nsevent/phase-swift.struct.md)
- [magnification](appkit/nsevent/magnification.md)
- [touches(matching:in:)](appkit/nsevent/touches(matching:in:).md)
- [allTouches()](appkit/nsevent/alltouches().md)
- [touches(for:)](appkit/nsevent/touches(for:).md)
- [coalescedTouches(for:)](appkit/nsevent/coalescedtouches(for:).md)
- [isMouseCoalescingEnabled](appkit/nsevent/ismousecoalescingenabled.md)
- [NSEvent.GestureAxis](appkit/nsevent/gestureaxis.md)

### Getting pressure information

- [pressure](appkit/nsevent/pressure.md)
- [stage](appkit/nsevent/stage.md)
- [stageTransition](appkit/nsevent/stagetransition.md)
- [pressureBehavior](appkit/nsevent/pressurebehavior-swift.property.md)
- [NSEvent.PressureBehavior](appkit/nsevent/pressurebehavior-swift.enum.md)

### Getting tablet proximity information

- [capabilityMask](appkit/nsevent/capabilitymask.md)
- [deviceID](appkit/nsevent/deviceid.md)
- [isEnteringProximity](appkit/nsevent/isenteringproximity.md)
- [pointingDeviceID](appkit/nsevent/pointingdeviceid.md)
- [pointingDeviceSerialNumber](appkit/nsevent/pointingdeviceserialnumber.md)
- [pointingDeviceType](appkit/nsevent/pointingdevicetype-swift.property.md)
- [NSEvent.PointingDeviceType](appkit/nsevent/pointingdevicetype-swift.enum.md)
- [systemTabletID](appkit/nsevent/systemtabletid.md)
- [tabletID](appkit/nsevent/tabletid.md)
- [uniqueID](appkit/nsevent/uniqueid.md)
- [vendorID](appkit/nsevent/vendorid.md)
- [vendorPointingDeviceType](appkit/nsevent/vendorpointingdevicetype.md)

### Getting tablet pointing information

- [absoluteX](appkit/nsevent/absolutex.md)
- [absoluteY](appkit/nsevent/absolutey.md)
- [absoluteZ](appkit/nsevent/absolutez.md)
- [buttonMask](appkit/nsevent/buttonmask-swift.property.md)
- [NSEvent.ButtonMask](appkit/nsevent/buttonmask-swift.struct.md)
- [rotation](appkit/nsevent/rotation.md)
- [tangentialPressure](appkit/nsevent/tangentialpressure.md)
- [tilt](appkit/nsevent/tilt.md)
- [vendorDefined](appkit/nsevent/vendordefined.md)

### Getting tracking area information

- [eventNumber](appkit/nsevent/eventnumber.md)
- [trackingNumber](appkit/nsevent/trackingnumber.md)
- [trackingArea](appkit/nsevent/trackingarea.md)
- [userData](appkit/nsevent/userdata.md)

### Getting custom event information

- [data1](appkit/nsevent/data1.md)
- [data2](appkit/nsevent/data2.md)

### Requesting and stopping periodic events

- [startPeriodicEvents(afterDelay:withPeriod:)](appkit/nsevent/startperiodicevents(afterdelay:withperiod:).md)
- [stopPeriodicEvents()](appkit/nsevent/stopperiodicevents().md)

### Monitoring app events

- [addGlobalMonitorForEvents(matching:handler:)](appkit/nsevent/addglobalmonitorforevents(matching:handler:).md)
- [addLocalMonitorForEvents(matching:handler:)](appkit/nsevent/addlocalmonitorforevents(matching:handler:).md)
- [removeMonitor(_:)](appkit/nsevent/removemonitor(_:).md)

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

- [location(in:)](appkit/nsevent/location(in:).md)

### Deprecated

- [context](appkit/nsevent/context.md)

### Initializers

- [init(CGEvent:)](appkit/nsevent/init(cgevent:)-8acvx.md)
- [init(coder:)](appkit/nsevent/init(coder:).md)

### Type Properties

- [isTouchSwipeNavigationEnabled](appkit/nsevent/istouchswipenavigationenabled.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Mouse, Keyboard, and Touch Events

- [NSTouch](appkit/nstouch.md)
