Defined in: hotkey-manager.ts:311
Singleton manager for hotkey registrations, including sequences.
This class provides a centralized way to register and manage keyboard hotkeys. It attaches one keydown and one keyup listener per target, regardless of how many hotkeys are registered.
Sequences (Vim-style hotkeys such as ['G', 'G']) match when every step is pressed within the timeout. Modifier-only events (Shift, Control, Alt, or Meta alone) neither advance nor reset a sequence, so chained modifier chords such as ['Shift+R', 'Shift+T'] work.
const manager = HotkeyManager.getInstance()
const save = manager.register('Mod+S', (event, context) => {
console.log('Save triggered!')
})
const top = manager.register(['G', 'G'], () => scrollToTop(), { timeout: 500 })
// Later, to unregister:
save.unregister()
top.unregister()readonly appHotkeys: Store<
| AppHotkeysStore<Readonly<Record<string, AppHotkey<string,
| HotkeyChord
| HotkeySequence
| null>>>>
| null>;Defined in: hotkey-manager.ts:340
The app hotkeys store published by a framework provider, so tools such as devtools can list declared hotkeys that are not registered.
readonly registrations: Store<Map<string, HotkeyRegistration>>;Defined in: hotkey-manager.ts:333
The TanStack Store containing all hotkey registrations, chords and sequences. Use this to subscribe to registration changes or access current registrations.
const manager = HotkeyManager.getInstance()
// Subscribe to registration changes
const unsubscribe = manager.registrations.subscribe(() => {
console.log('Registrations changed:', manager.registrations.state.size)
})
// Access current registrations
for (const [id, reg] of manager.registrations.state) {
console.log(reg.hotkey, reg.options.enabled)
}destroy(): void;Defined in: hotkey-manager.ts:1042
Destroys the manager and removes all listeners.
void
getRegistrationCount(): number;Defined in: hotkey-manager.ts:1012
Gets the number of registered hotkeys, chords and sequences.
number
isRegistered(hotkey, target?): boolean;Defined in: hotkey-manager.ts:1023
Checks if a specific hotkey is registered.
The chord or sequence to check
Optional target element to match (if provided, both hotkey and target must match)
boolean
True if a matching registration exists
register<T>(
hotkey,
callback,
options?): HotkeyRegistrationHandle<HotkeyOptionsFor<T>>;Defined in: hotkey-manager.ts:410
Registers a hotkey handler and returns a handle for updating the registration.
Pass a chord ('Mod+S' or a RawHotkey object) or a sequence (['G', 'G']). A one-step sequence registers as its chord. Chords accept requireReset; sequences accept timeout.
The returned handle allows updating the callback and options without re-registering, which is useful for avoiding stale closures in React.
T extends RegisterableHotkey
T
A chord string, RawHotkey object, or sequence
The function to call when the hotkey is pressed
Options for the hotkey behavior
HotkeyRegistrationHandle<HotkeyOptionsFor<T>>
A handle for managing the registration
const handle = manager.register('Mod+S', callback)
// Update callback without re-registering (avoids stale closures)
handle.callback = newCallback
// Update options
handle.setOptions({ enabled: false })
// Unregister when done
handle.unregister()resetSequenceProgress(): void;Defined in: hotkey-manager.ts:957
Resets the progress of every in-progress sequence.
void
triggerRegistration(id): boolean;Defined in: hotkey-manager.ts:975
Triggers a registration's callback programmatically from devtools. Creates a synthetic KeyboardEvent from the chord (or a sequence's last step) and invokes the callback.
string
The registration ID to trigger
boolean
True if the registration was found and triggered
static getInstance(): HotkeyManager;Defined in: hotkey-manager.ts:359
Gets the singleton instance of HotkeyManager.
HotkeyManager
static resetInstance(): void;Defined in: hotkey-manager.ts:369
Resets the singleton instance. Useful for testing.
void