useHotkey
useHotkey(
combo,handler,options?):void
Defined in: src/hooks/useHotkey/useHotkey.ts:155
Bind a single keyboard combo to a callback.
Combos use the same +-separated string format as MenuBar’s shortcut
prop: "Ctrl+S", "Cmd+Shift+P", "Escape". Modifiers: Ctrl, Cmd
(= Meta), Alt / Option, Shift. Cmd automatically maps to Ctrl on
non-Mac platforms via getPlatform().
The handler reference is stable — passing a fresh inline function on every render is safe and does not re-subscribe the underlying listener.
Parameters
Section titled “Parameters”string
handler
Section titled “handler”(event) => void
options?
Section titled “options?”UseHotkeyOptions = {}
Returns
Section titled “Returns”void
Example
Section titled “Example”useHotkey('Ctrl+S', e => save(), { preventDefault: true });useHotkey('Escape', () => setOpen(false));useHotkey('Cmd+K', () => openCommandPalette()); // Cmd on Mac, Ctrl elsewhere