Overview
Hotkey listener composable with key combination and sequence support. Platform-aware with automatic cleanup.Features
- Key combination support (
ctrl+k,shift+enter) - Key sequence support (
g-hfor GitHub-style shortcuts) - Platform-aware modifiers (Mac: cmd→meta, others: cmd→ctrl)
- Input focus detection (skip when typing in inputs)
- Sequence timeout with automatic reset
- Key alias normalization
- Pause/resume/stop functionality
- Automatic cleanup on scope disposal
- SSR-safe (no-op when not in browser)
Function Signature
Parameters
The hotkey string (e.g., ‘ctrl+k’, ‘g-h’). Can be reactive.
The function to call when the hotkey is triggered.
The keyboard event type to listen for.
Whether to trigger the callback when an input element is focused.
Whether to prevent the default browser action.
Whether to stop event propagation.
Timeout in ms before a key sequence resets.
Return Value
Whether the hotkey listener is currently active.
Whether the hotkey listener is currently paused.
Pause listening (removes listener but keeps configuration).
Resume listening after pause.
Stop listening and clean up.
Examples
Simple combination
Key sequence (GitHub-style)
With options
Pause/resume control
Reactive hotkey
Multiple modifiers
Arrow key sequences
Platform-aware shortcuts
Supported Key Aliases
Modifiers
ctrl/controlshiftalt/optionmeta/cmd/command
Arrow Keys
up→ArrowUpdown→ArrowDownleft→ArrowLeftright→ArrowRight
Common Keys
esc→Escapespace→return→Enterdel→Delete
Key Combinations
Use+ to combine keys:
Key Sequences
Use- to create sequences:
Input Focus Detection
By default, hotkeys are ignored when text inputs are focused:<input type="text">,<input type="email">, etc.<textarea>- Elements with
contentEditable - Elements with ARIA roles:
textbox,searchbox,combobox,spinbutton
inputs: true to override this behavior.
Notes
- Platform-aware:
cmdmaps tometaon Mac,ctrlelsewhere - Sequences reset after
sequenceTimeoutmilliseconds - Input detection helps prevent conflicts with form fields
- SSR-safe: returns valid API structure with no-op listeners