hammerspoon2-docs
    Preparing search index...

    Function bindHotkey

    • Bind a keyboard shortcut using an event tap. Unlike hs.hotkey.bind(), this supports the fn modifier and left/right modifier key distinction (e.g. leftCmd, rightAlt). The hotkey is active immediately and consumes (suppresses) the key events. It's important to note that this a much heavier-weight tool than hs.hotkey - every single key you press will be examined by Hammerspoon to see if it matches one of the EventTap hotkeys (where hs.hotkey relies on macOS to efficiently deliver only matching keypresses). Please consider this when choosing to use hs.eventtap for hotkeys. Requires Accessibility permission. ctrl, fn) and side-specific names (leftCmd, rightCmd, leftAlt, rightAlt, leftCtrl, rightCtrl, leftShift, rightShift). macOS reports fn as held on every press of the arrow keys, F-keys, help, home, end, page up/down, forward delete and keypad clear, so on those keys a hotkey with fn also fires without it (one without fn still works). current keyboard layout (see hs.eventtap.followsKeyboardLayout), or a numeric virtual key code, which always means the same physical key each key repeat while the whole combination stays held, or null repeat shows the combination is no longer held (e.g. a modifier was let go first), or null. After that, the key's remaining repeats and its release pass through as normal.

      Parameters

      • mods: string[]

        An array of modifier key strings. Supports generic names (cmd, shift, alt,

      • key: string | number

        A key name or character (e.g., "a", "space", "f1"), resolved through the

      • onPressed: (() => void) | null

        Called when the key combination is pressed, and again for

      • onReleased: (() => void) | null

        Called when the key is released, or as soon as a key

      Returns HSEventTapHotkey | null

      An HSEventTapHotkey object, or null if binding failed

      The hotkey stays bound until you disable it, even if you don't keep a reference to it.