---
title: "addGlobalMonitorForEvents(matching:handler:)"
framework: appkit
role: symbol
role_heading: Type Method
path: "appkit/nsevent/addglobalmonitorforevents(matching:handler:)"
---

# addGlobalMonitorForEvents(matching:handler:)

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

## Declaration

```swift
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 doc://com.apple.appkit/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

Return Value An event handler object.

## Discussion

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 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 NSRightMouseDragged NSOtherMouseDragged NSLeftMouseUp NSRightMouseUp NSOtherMouseUp NSLeftMouseDown NSRightMouseDown NSOtherMouseDown NSMouseMoved NSFlagsChanged NSScrollWheel NSTabletPoint NSTabletProximity NSKeyDown (Key repeats are determined using the isARepeat property.)

## See Also

### Monitoring app events

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