This is an advanced guide. Inside Solid components, createHotkey and createHotkeys register hotkeys, clean them up on disposal, apply provider defaults and scopes, and follow signals. Use HotkeyManager directly only outside Solid components, such as inside third-party chart or canvas wrappers.
All hotkeys on a page share a single HotkeyManager instance that owns the DOM event listeners, matches key presses, tracks sequence progress, and evaluates scopes. Access it with getHotkeyManager():
import { getHotkeyManager } from '@tanstack/solid-hotkeys'
const manager = getHotkeyManager()manager.register accepts the same hotkeys and options as createHotkey and returns a registration handle:
const handle = manager.register('Mod+K', () => openCommandPalette())
handle.setOptions({ enabled: false }) // Merges updated options
handle.callback = () => openSearch() // Updates callback in place
handle.unregister() // Removes the registrationKeep a few differences from createHotkey in mind:
For example, wiring shortcuts inside a vanilla chart plugin:
import { getHotkeyManager } from '@tanstack/solid-hotkeys'
export function attachChartHotkeys(chart: Chart, element: HTMLElement) {
const manager = getHotkeyManager()
const handles = [
manager.register('I', () => chart.zoomIn(), { target: element }),
manager.register('O', () => chart.zoomOut(), { target: element }),
]
return () => handles.forEach((handle) => handle.unregister())
}Inside components, read registrations with createHotkeyRegistrations (see List the hotkeys on screen). Outside components, query the manager directly:
manager.getRegistrationCount() // Total registered hotkeys
manager.isRegistered('Mod+S') // Whether any registration matches
manager.isRegistered('Escape', panelElement) // Whether one matches on that targetisRegistered uses canonical matching just like duplicate detection, so 'Meta+S' matches a 'Mod+S' registration on macOS.
manager.registrations reads and subscribes like a TanStack Store holding a Map of registrations by ID:
const subscription = manager.registrations.subscribe((registrations) => {
console.log(`${registrations.size} hotkeys registered`)
})
subscription.unsubscribe()Because this store updates whenever a hotkey fires or a sequence step advances, keep subscribers lightweight. Raw registrations include callback. For the callback-free shape returned by createHotkeyRegistrations, pass a registration to toHotkeyRegistrationView.
Inside Solid, define scopes with HotkeysProvider (see HotkeysProvider & Scopes). For non-Solid UI, such as a dialog mounted by an imperative library, activate a scope directly on the manager and pass that scope to its registrations:
const releaseScope = manager.activateScope('image-viewer', { exclusive: true })
const close = manager.register('Escape', () => viewer.close(), {
scope: 'image-viewer',
})
// Clean up when the viewer closes
close.unregister()
releaseScope()activateScope returns a release function, and a scope remains active until every activation of it has been released. It accepts two options:
Call manager.isScopeActive(scope) to check whether a scope can currently fire, or inspect each registration's status (see List the hotkeys on screen).
manager.scopes is a store with four fields:
Inside Solid components, read the same state reactively with createHotkeyScopesState. It updates when scopes activate or release:
import { Show } from 'solid-js'
import { createHotkeyScopesState } from '@tanstack/solid-hotkeys'
function KeyboardOwner() {
const scopes = createHotkeyScopesState()
return (
<Show when={scopes().exclusive}>
{(owner) => <p>Shortcuts belong to {owner()}</p>}
</Show>
)
}The devtools display the same live scope state without writing code.
Call manager.resetSequenceProgress() to clear partial progress on all active sequences, such as when an external UI action cancels a pending command.
To match a sequence inside your own keydown listener without registering on HotkeyManager, use createSequenceMatcher:
import { createSequenceMatcher } from '@tanstack/solid-hotkeys'
const matcher = createSequenceMatcher(['G', 'G'], { timeout: 1000 })
document.addEventListener('keydown', (event) => {
if (matcher.match(event)) scrollToTop()
})The matcher tracks its own state via getProgress() and reset(). Standalone matchers don't check ignoreInputs, call preventDefault(), or evaluate scopes, so handle those in your listener if needed.
For resetting HotkeyManager and KeyStateTracker between tests and pinning the platform, see Testing.
For resetting HotkeyManager and KeyStateTracker between tests and pinning the platform, see Testing.
See the HotkeyManager reference for the full method list.