hammerspoon2-docs
    Preparing search index...

    Function bind

    • Bind a hotkey cmd / command / ⌘, shift / ⇧, alt / option / ⌥, ctrl / control / ⌃. through the current keyboard layout (see hs.keycodes.map), or a numeric virtual key code, which always means the same physical key

      Parameters

      • mods: string[]

        An array of modifier key strings (e.g., ["cmd", "shift"]). Supported names:

      • key: string | number

        The key: a name or character (e.g. "a", "space", "return", "f1"), resolved

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

        A JavaScript function to call when the hotkey is pressed, or null for no callback

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

        A JavaScript function to call when the hotkey is released, or null/omitted for no callback

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

        A JavaScript function to call repeatedly while the hotkey is held down, or null/omitted for no repeat

      Returns HSHotkey | null

      A hotkey object, or null if binding failed (including when none of the callbacks is a function — at least one is required)

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