API Docs

An input event captured or constructed by hs.eventtap.

Objects of this type are passed to event tap callbacks and can also be created directly via the factory methods on hs.eventtap. Properties can be inspected and modified before the event is passed through or posted back to the system.

Properties

type

number

The numeric event type, matching a value in hs.eventtap.eventTypes

keyCode

number

The virtual key code for keyboard events (get/set)

rawFlags

number

The raw modifier flags bitmask (get/set). Use values from hs.eventtap.modifierFlags.

flags

string[]

An array of active modifier key names (e.g. ["cmd", "shift"]) (get/set).

When a device-specific modifier is detected, both the generic and side-specific names are included — e.g. pressing the left Command key yields ["cmd", "leftCmd"].

Setting this replaces the event's modifiers with the named ones, accepting the same names as hs.eventtap.keyStroke() ("cmd", "shift", "alt", "ctrl", "fn", "capslock", and the side-specific forms such as "rightCmd"). Unknown names are ignored. This only changes the event's flags: an application that tracks modifier key presses itself may also need to see the modifier keys go down and up, which hs.eventtap.keyStroke(mods, key, app) does for you.

location

{[key: string]: number}

The event's screen position as {x, y} in Hammerspoon screen coordinates (top-left origin of primary display, y increases downward, matching hs.screen).

buttonNumber

number

The mouse button number for mouse events (0=left, 1=right, 2=middle)

scrollingDeltaX

number

The horizontal scroll delta for scroll wheel events

scrollingDeltaY

number

The vertical scroll delta for scroll wheel events

characters

string

The Unicode characters produced by this keyboard event, or null for non-keyboard events

systemKey

[String: Any]

For a system key event (media, volume, brightness and other special keys), an object describing the key; for any other event, null.

The object has key (a name from hs.eventtap.systemKeys, or "unknown"), keyCode (the numeric system key code), isDown (true for key down, false for key up) and isRepeat (true if the key is auto-repeating). Watch for these events with hs.eventtap.eventTypes.systemDefined; other kinds of system-defined event, which don't represent a key, also yield null.

Methods

duplicate() -> HSEventTapEvent

Create an independent copy of this event

duplicate() -> HSEventTapEvent
HSEventTapEvent
A new HSEventTapEvent with the same properties, or null if the copy failed
const copy = event.duplicate()
copy.keyCode = 0  // modify the copy
copy.post()

post(app) -> None

Post this event to the HID event stream, optionally targeting a specific application.

When app is omitted or null, the event is posted to the global HID stream and delivered by the OS as if a real input device generated it. When an application is provided, the event is delivered directly to that process by PID.

post(app) -> None
Name Type Description
app HSApplication The application to target, or null/omit to post globally
None
const evt = hs.eventtap.makeKeyEvent("a", true)
evt.post()                              // post globally

const safari = hs.application.find("Safari")
if (safari) evt.post(safari)            // post directly to Safari