<!--
{
  "availability" : [
    "macOS: 10.6.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSEvent/addGlobalMonitorForEvents(matching:handler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSEvent(cm)addGlobalMonitorForEventsMatchingMask:handler:"
  },
  "title" : "addGlobalMonitorForEvents(matching:handler:)"
}
-->

# addGlobalMonitorForEvents(matching:handler:)

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

```
class func addGlobalMonitorForEvents(matching mask: NSEvent.EventTypeMask, handler block: @escaping (NSEvent) -> Void) -> Any?
```

## Parameters

`mask`

An event mask specifying which events you wish to monitor. See [`NSEvent.EventTypeMask`](/documentation/AppKit/NSEvent/EventTypeMask) for possible values.

`block`

The event handler block object. It is passed the event to monitor. You are unable to change the event, merely observe it.

## Return Value

An event handler object.

## Discussion

Events are delivered asynchronously to your app and you can only observe the event; you cannot modify or otherwise prevent the event from being delivered to its original target application.

Key-related events may only be monitored if accessibility is enabled or if your application is trusted for accessibility access (see <doc://com.apple.documentation/documentation/applicationservices/1460720-axisprocesstrusted>).

Note that your handler will not be called for events that are sent to your own application.

### Special Considerations

In OS X v 10.6, event monitors are only able to monitor the following event types:

- [`NSLeftMouseDragged`](/documentation/AppKit/NSLeftMouseDragged)
- [`NSRightMouseDragged`](/documentation/AppKit/NSRightMouseDragged)
- [`NSOtherMouseDragged`](/documentation/AppKit/NSOtherMouseDragged)
- [`NSLeftMouseUp`](/documentation/AppKit/NSLeftMouseUp)
- [`NSRightMouseUp`](/documentation/AppKit/NSRightMouseUp)
- [`NSOtherMouseUp`](/documentation/AppKit/NSOtherMouseUp)
- [`NSLeftMouseDown`](/documentation/AppKit/NSLeftMouseDown)
- [`NSRightMouseDown`](/documentation/AppKit/NSRightMouseDown)
- [`NSOtherMouseDown`](/documentation/AppKit/NSOtherMouseDown)
- [`NSMouseMoved`](/documentation/AppKit/NSMouseMoved)
- [`NSFlagsChanged`](/documentation/AppKit/NSFlagsChanged)
- [`NSScrollWheel`](/documentation/AppKit/NSScrollWheel)
- [`NSTabletPoint`](/documentation/AppKit/NSTabletPoint)
- [`NSTabletProximity`](/documentation/AppKit/NSTabletProximity)
- [`NSKeyDown`](/documentation/AppKit/NSKeyDown) (Key repeats are determined using the [`isARepeat`](/documentation/AppKit/NSEvent/isARepeat) property.)

---

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)