Contents

addLocalMonitorForEvents(matching:handler:)

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

Declaration

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

Parameters

  • mask:

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

  • block:

    The event handler block object. It is passed the event to monitor. You can return the event unmodified, create and return a new NSEvent object, or return nil to stop the dispatching of the event.

Return Value

An event handler object.

Discussion

Your handler will not be called for events that are consumed by nested event-tracking loops such as control tracking, menu tracking, or window dragging; only events that are dispatched through the applications sendEvent(_:) method will be passed to your handler.

Special Considerations

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

See Also

Monitoring app events