API Docs

Object representing a system-wide hotkey. You should not create these objects directly, but rather, use the methods in hs.hotkey to instantiate these.

Properties

mods

string[]

The modifier keys this hotkey was bound with, as originally passed to bind()/create()

key

string | number

The key this hotkey was bound with, as originally passed to bind()/create()

keyCode

number

The virtual key code this hotkey is currently registered on. For a hotkey bound by key name this follows the keyboard layout (see hs.hotkey.followsKeyboardLayout).

message

string | null

An optional description of what this hotkey does, or null if none was set. When set, it is shown as an on-screen toast via hs.ui.alert() (duration controlled by hs.hotkey.alertDuration) just before the hotkey's callback runs: before the pressed callback if one exists, otherwise before the released callback if one exists.

onRepeat

(() => void) | null

The callback function to be called repeatedly while the hotkey is held down, or null to remove it. Repeats at the system keyboard-repeat delay/interval, matching how held-down keys repeat elsewhere in macOS.

onPressed

(() => void) | null

The callback function to be called when the hotkey is pressed, or null to remove it

onReleased

(() => void) | null

The callback function to be called when the hotkey is released, or null to remove it

Methods

enable() -> boolean

Enable the hotkey

enable() -> boolean
boolean
True if the hotkey was enabled, otherwise False
An enabled hotkey, and its callbacks, stay alive until it's disabled, even if you don't keep a reference to it
const hk = hs.hotkey.bind(["cmd"], "h", () => {})
hk.enable()

disable() -> None

Disable the hotkey

disable() -> None
None
const hk = hs.hotkey.bind(["cmd"], "h", () => {})
hk.disable()

isEnabled() -> boolean

Check if the hotkey is currently enabled

isEnabled() -> boolean
boolean
True if the hotkey is enabled, otherwise False
const hk = hs.hotkey.bind(["cmd"], "h", () => {})
console.log(hk.isEnabled())

destroy() -> None

Disable and permanently remove this hotkey, releasing all associated resources

destroy() -> None
None
const hk = hs.hotkey.bind(["cmd"], "h", () => {})
hk.destroy()