Hotkeys API Reference
- HotkeyManager
- getHotkeyManager
- HotkeyScopesState
- Hotkey
- HotkeyChord
- HotkeySequence
- RegisterableHotkey
- RegisterableHotkeyChord
- RegisterableHotkeySequence
- RawHotkeyChord
- HotkeyOptions
- HotkeyChordOptions
- HotkeySequenceOptions
- HotkeyOptionsFor
- HotkeyRegistrationHandle
- HotkeyRegistrationView
- HotkeyChordRegistrationView
- HotkeySequenceRegistrationView
- HotkeyRegistrationStatus
- toHotkeyRegistrationView
- HotkeyCallback
- HotkeyCallbackContext
- HotkeyChordCallbackContext
- HotkeySequenceCallbackContext
- HotkeyCallbackContextFor
- HotkeyMeta
- ConflictBehavior
- isHotkeySequence
- simplifyHotkey
- createSequenceMatcher
- DEFAULT_SEQUENCE_TIMEOUT
- AppHotkeysProvider
- HotkeysProvider
- useDefaultHotkeysOptions
- useFormatForDisplay
- useHotkey
- useHotkeyRegistrations
- useHotkeyScopesState
- useHotkeys
- useHotkeysContext
- AppHotkeysProviderProps
- HotkeysProviderOptions
- HotkeysProviderProps
- UseHotkeyChordOptions
- UseHotkeyCommonOptions
- UseHotkeyDefinition
- UseHotkeyOptions
- UseHotkeyOptionsFor
- UseHotkeySequenceOptions
- UseHotkeyTarget
App Hotkeys API Reference
- defineAppHotkeys
- AppHotkeysStore
- installAppHotkeysStore
- provideAppHotkeys
- publishAppHotkeysStore
- AppHotkey
- AppHotkeyInput
- AppHotkeyOptions
- AppHotkeyListItem
- AppHotkeyStatus
- AppHotkeysState
- AppHotkeysStoreOptions
- CustomHotkeys
- Register
- AppHotkeyId
- RegisteredAppHotkeys
- isAppHotkey
- isCustomHotkey
- resolveAppHotkey
- useAppHotkeyList
- useAppHotkeys
- useCustomHotkeys
- UseCustomHotkeysResult
- UseAppHotkeyOptions
Key hold & held keys API Reference
Hotkey Recorder API Reference
- HotkeyRecorder
- HotkeyRecorderOptions
- HotkeyChordRecorderOptions
- HotkeySequenceRecorderOptions
- HotkeyRecorderState
- HotkeyRecorderCommitKeys
- HotkeyRecorderValidationContext
- HotkeyChordRecorderValidationContext
- HotkeySequenceRecorderValidationContext
- RecorderOptions
- RecorderRejection
- RecorderKeyMode
- findHotkeyConflicts
- HotkeyConflict
- HotkeyConflictOptions
- useHotkeyRecorder
- ReactHotkeyRecorder
Normalization & format API Reference
- formatForDisplay
- FormatDisplayOptions
- DisplayHotkey
- DisplayHotkeyChord
- detectPlatform
- HotkeyPlatform
- formatHotkey
- normalizeHotkey
- parseHotkey
- parseKeyboardEvent
- ParsedHotkeyChord
- matchesKeyboardEvent
- areHotkeysEqual
- validateHotkey
- checkHotkey
- assertValidHotkey
- ValidationResult
- ValidatableHotkey
- LogicalKey
- PhysicalKey
- PhysicalKeyCode
- KEY_DISPLAY_SYMBOLS
- PUNCTUATION_KEY_DISPLAY_LABELS
- MAC_MODIFIER_SYMBOLS
- MAC_MODIFIER_LABELS
- WINDOWS_MODIFIER_LABELS
- LINUX_MODIFIER_LABELS
- MODIFIER_ALIASES
- MODIFIER_ORDER
- MODIFIER_KEYS
HotkeyManager
Defined in: hotkey-manager.ts:701
Properties#
appHotkeys#
readonly appHotkeys: Store<AppHotkeysStore | null>;Defined in: hotkey-manager.ts:728
The app hotkeys store published by a framework provider, so tools such as devtools can list declared hotkeys that are not registered.
registrations#
readonly registrations: Store<Map<string, HotkeyRegistration>>;Defined in: hotkey-manager.ts:721
The TanStack Store containing all hotkey registrations, chords and sequences. Use this to subscribe to registration changes or access current registrations.
Example#
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)
}scopes#
readonly scopes: Store<HotkeyScopesState>;Defined in: hotkey-manager.ts:731
Active scopes. Subscribe to show which hotkeys are suspended.
Methods#
activateScope()#
activateScope(scope, options?): () => void;Defined in: hotkey-manager.ts:865
Activates a scope until the returned function is called. Activations are counted, so a scope stays active until every activation is released. Framework providers call this while mounted.
When active scopes share a hotkey, a nested scope takes precedence over its ancestors, and otherwise the most recently activated scope wins. The same order picks the exclusive scope when several are active, and only that scope's allow list applies.
Parameters#
scope#
string
options?#
ActivateHotkeyScopeOptions = {}
Returns#
() => void
Example#
const release = manager.activateScope('dialog', { exclusive: true })
// Only hotkeys with scope 'dialog', or scopes nested in it, fire now.
release()
manager.activateScope('dialog', { exclusive: { allow: ['global'] } })
// Hotkeys with scope 'global' fire too.destroy()#
destroy(): void;Defined in: hotkey-manager.ts:2271
Destroys the manager and removes all listeners.
Returns#
void
getRegistrationCount()#
getRegistrationCount(): number;Defined in: hotkey-manager.ts:2203
Gets the number of registered hotkeys, chords and sequences.
Returns#
number
hasActiveRegistration()#
hasActiveRegistration(hotkey): boolean;Defined in: hotkey-manager.ts:2241
Checks whether a hotkey can fire now: at least one registration is enabled, in an active scope, and listening where key presses go. A registration on document or window always is; one on an element is only while focus is inside that element. An app hotkey matches registrations by id, so custom hotkeys apply.
Parameters#
hotkey#
| RegisterableHotkey | AppHotkey<string, HotkeyChord | HotkeySequence | null> | null | undefined
A chord, sequence, or app hotkey. No hotkey (undefined, null, or '') returns false.
Returns#
boolean
True if a registration that can fire exists
isRegistered()#
isRegistered(hotkey, target?): boolean;Defined in: hotkey-manager.ts:2214
Checks if a specific hotkey is registered.
Parameters#
hotkey#
The chord or sequence to check
target?#
Optional target element to match (if provided, both hotkey and target must match)
Returns#
boolean
True if a matching registration exists
isScopeActive()#
isScopeActive(scope?): boolean;Defined in: hotkey-manager.ts:904
Whether hotkeys in a scope can fire: the scope is 'global' or activated, and either no scope is exclusive or this scope is the exclusive one, nested in it, or allowed by it.
Parameters#
scope?#
string = GLOBAL_SCOPE
Returns#
boolean
register()#
register<T>(
hotkey,
callback,
options?
): HotkeyRegistrationHandle<HotkeyOptionsFor<T>>;Defined in: hotkey-manager.ts:1122
Registers a hotkey handler and returns a handle for updating the registration.
Pass a chord ('Mod+S' or a RawHotkeyChord 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.
Type Parameters#
T#
T extends RegisterableHotkey
Parameters#
hotkey#
T
A chord string, RawHotkeyChord object, or sequence
callback#
HotkeyCallback<HotkeyCallbackContextFor<T>>
The function to call when the hotkey is pressed
options?#
Options for the hotkey behavior
Returns#
HotkeyRegistrationHandle<HotkeyOptionsFor<T>>
A handle for managing the registration
Example#
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()#
resetSequenceProgress(): void;Defined in: hotkey-manager.ts:2188
Resets the progress of every in-progress sequence.
Returns#
void
suspendCharacterKeys()#
suspendCharacterKeys(): () => void;Defined in: hotkey-manager.ts:931
Suspends document-level character key shortcuts until you call the returned function, so apps can let users turn off single-key shortcuts for WCAG 2.1.4 (Character Key Shortcuts). A character key shortcut is a hotkey whose every step types a character, alone or with Shift, such as K, ?, Shift+K, Space, or ['G', 'H']. Hotkeys with Control, Alt, or Meta, non-character keys such as Escape or F1, and hotkeys targeted at an element other than the body or the root element keep working. Enabled hotkeys that are suspended report the status 'suspended'.
Suspensions are counted, so character keys stay suspended until every returned resume function runs. Framework providers call this while mounted with suspendCharacterKeys.
Returns#
() => void
Example#
const resume = manager.suspendCharacterKeys()
// `K` and `['G', 'H']` don't fire; `Mod+K` and `Escape` do.
resume()trigger()#
trigger(id, event?): boolean;Defined in: hotkey-manager.ts:2176
Runs a registration's callback without a key press, as for a command palette entry or a devtools button. The callback gets the same context as a key press. Without event, it gets a keydown (or the registration's eventType) for the hotkey, or a sequence's last step, that is never dispatched, so event.isTrusted is false.
Only enabled is checked. Scopes, focus, ignoreInputs, and requireReset don't apply, since the caller chose to run it, and preventDefault and stopPropagation aren't applied to event. Counts the call in triggerCount, ends a sequence's attempt in progress, and notifies subscribers like a key press. An error the callback throws is reported in a microtask, as for a key press, and trigger still returns true.
Parameters#
id#
string
The registration id, such as a view's or a handle's id
event?#
KeyboardEvent
The event to pass to the callback
Returns#
boolean
Whether the callback ran: false when the id isn't registered or the registration is disabled
getInstance()#
static getInstance(): HotkeyManager;Defined in: hotkey-manager.ts:833
Gets the singleton instance of HotkeyManager.
Returns#
HotkeyManager
resetInstance()#
static resetInstance(): void;Defined in: hotkey-manager.ts:840
Resets the singleton instance. Useful for testing.
Returns#
void