hammerspoon2-docs
    Preparing search index...

    Function addWatcher

    • Create an event tap that calls a function for matching events. Call .start() to activate it. The callback receives an HSEventTapEvent. For modify taps (listenOnly omitted or false), return hs.eventtap.consume (false) to suppress the event or hs.eventtap.emit (true) to pass it through. For listen-only taps the callback's return value is ignored — events are always delivered to other applications. Requires Accessibility permission.

      Parameters

      • types: number[]

        An array of event type integers from hs.eventtap.eventTypes

      • callback: (event: HSEventTapEvent) => boolean | undefined

        Function called for each matching event. The return value is only meaningful for modify taps.

      • listenOnly: boolean

        If true, the tap receives events but cannot modify or suppress them. Omit or pass false for a modify tap (the default).

      Returns HSEventTap | null

      An HSEventTap watcher, or null if the tap could not be created

      event tap watchers will not be automatically destroyed by JavaScript garbage collection. You MUST call removeWatcher() if you want to dispose of a watcher.