API Docs

A group of hotkeys that are activated and deactivated together.

Obtain instances via hs.hotkey.modal.create() — do not instantiate directly.

Example

const m = hs.hotkey.modal.create(['cmd', 'shift'], 'h')
m.bind([], 'j', () => console.log('j pressed in modal'), null)
m.enterFn = () => console.log('modal entered')
m.exitFn  = () => console.log('modal exited')
// Press Cmd+Shift+H to enter, then J triggers the modal hotkey

Properties

enterFn

function | null
Called when the modal is entered

exitFn

function | null
Called when the modal is exited

isActive

boolean
Whether the modal is currently active

Methods

bind(mods, key, callbackPressed, callbackReleased) -> HSHotkeyModal

Add a hotkey that is active only while this modal is entered
bind(mods, key, callbackPressed, callbackReleased) -> HSHotkeyModal
Name Type Description
mods string[] Modifier keys for the hotkey
key string Key name for the hotkey
callbackPressed function Called when the key is pressed, or null
callbackReleased function Called when the key is released, or null
HSHotkeyModal
This modal, for chaining
m.bind(['shift'], 'a', () => console.log('shift-a'), null)
 .bind([], 'escape', () => m.exit(), null)

enter() -> HSHotkeyModal

Activate the modal: enable its hotkeys and disable the trigger hotkey
enter() -> HSHotkeyModal
HSHotkeyModal
This modal, for chaining
m.enter()

exit() -> HSHotkeyModal

Deactivate the modal: disable its hotkeys and re-enable the trigger hotkey
exit() -> HSHotkeyModal
HSHotkeyModal
This modal, for chaining
m.exit()

destroy() -> None

Destroy the modal and all its hotkeys without calling exitFn
destroy() -> None
None
m.destroy()