API Docs

An event tap watcher that intercepts input events from the system.

Obtain instances via hs.eventtap.addWatcher() — do not instantiate directly.

Monitoring keyboard events

const tap = hs.eventtap.addWatcher([hs.eventtap.eventTypes.keyDown], (event) => {
    console.log("Key pressed: " + event.keyCode)
})

Properties

identifier

string
A unique identifier for this tap

listenOnly

boolean
Whether this tap was created as listen-only (events are observed but never modified or suppressed)

Methods

start() -> HSEventTap

Start receiving events. Requires Accessibility permission.
start() -> HSEventTap
HSEventTap
This tap, for chaining
const tap = hs.eventtap.addWatcher([hs.eventtap.eventTypes.keyDown], (event) => {
    console.log("Key: " + event.keyCode)
})
tap.start()

stop() -> HSEventTap

Stop receiving events
stop() -> HSEventTap
HSEventTap
This tap, for chaining
tap.stop()

setCallback(callback) -> HSEventTap

Replace the callback function
setCallback(callback) -> HSEventTap
Name Type Description
callback function A function called for each matching event. Return false to consume (suppress) the event; return anything else to pass it through.
HSEventTap
This tap, for chaining
tap.setCallback((event) => {
    console.log("Key: " + event.keyCode)
    return false  // consume the event
})

isEnabled() -> boolean

Whether this tap is currently active
isEnabled() -> boolean
boolean
True if the tap is running
console.log("Running: " + tap.isEnabled())

isCreated() -> boolean

Whether this tap has been registered with macOS
isCreated() -> boolean
boolean
True if the tap has been created
console.log("Created: " + tap.isCreated())