Type Method


Installs an event monitor that receives copies of events posted to other applications.


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



An event mask specifying which events you wish to monitor. See NSEvent.EventTypeMask for possible values.


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.


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

See Also

Monitoring Application Events

class func addLocalMonitorForEvents(matching: NSEvent.EventTypeMask, handler: (NSEvent) -> NSEvent?) -> Any?

Installs an event monitor that receives copies of events posted to this application before they are dispatched.

class func removeMonitor(Any)

Remove the specified event monitor.