hs.hotkey
ModuleModule for creating and managing system-wide hotkeys
Types
This module provides the following types:
Properties
This module has no properties.
Methods
hs.hotkey.bind(mods, key, callbackPressed, callbackReleased) -> HSHotkey
Bind a hotkey
Declaration
hs.hotkey.bind(mods, key, callbackPressed, callbackReleased) -> HSHotkey
Parameters
| Name | Type | Description |
|---|---|---|
| mods | JSValue | An array of modifier key strings (e.g., ["cmd", "shift"]) |
| key | string | The key name or character (e.g., "a", "space", "return") |
| callbackPressed | JSValue | A JavaScript function to call when the hotkey is pressed |
| callbackReleased | JSValue | A JavaScript function to call when the hotkey is released |
Returns
HSHotkey
A hotkey object, or nil if binding failed
Example
hs.hotkey.bind(["cmd","shift"], "h", () => {
console.log("Hello!")
})
hs.hotkey.bindSpec(mods, key, message, callbackPressed, callbackReleased) -> HSHotkey
Bind a hotkey with a message description
Declaration
hs.hotkey.bindSpec(mods, key, message, callbackPressed, callbackReleased) -> HSHotkey
Parameters
| Name | Type | Description |
|---|---|---|
| mods | JSValue | An array of modifier key strings |
| key | string | The key name or character |
| message | string | A description of what this hotkey does (currently unused, for future features) |
| callbackPressed | JSValue | A JavaScript function to call when the hotkey is pressed |
| callbackReleased | JSValue | A JavaScript function to call when the hotkey is released |
Returns
HSHotkey
A hotkey object, or nil if binding failed
Example
hs.hotkey.bindSpec(["cmd"], "space", "Spotlight-like", () => {
console.log("pressed")
}, null)
hs.hotkey.getKeyCodeMap() -> {[key: string]: number}
Get the system-wide mapping of key names to key codes
Declaration
hs.hotkey.getKeyCodeMap() -> {[key: string]: number}
Returns
{[key: string]: number}
A dictionary mapping key names to numeric key codes
Example
console.log(hs.hotkey.getKeyCodeMap())
hs.hotkey.getModifierMap() -> {[key: string]: number}
Get the mapping of modifier names to modifier flags
Declaration
hs.hotkey.getModifierMap() -> {[key: string]: number}
Returns
{[key: string]: number}
A dictionary mapping modifier names to their numeric values
Example
console.log(hs.hotkey.getModifierMap())