TanStack Hotkeys provides the useHotkeySequenceRecorder hook for building UIs where users record multi-chord sequences (Vim-style shortcuts). Each step is captured like a single hotkey chord; users finish with Enter by default, or you can use manual commit and optional idle timeout.
import { useHotkeySequenceRecorder, formatForDisplay } from '@tanstack/react-hotkeys'
import type { HotkeySequence } from '@tanstack/react-hotkeys'
function HotkeySequenceRecorder() {
const recorder = useHotkeySequenceRecorder({
onRecord: (sequence: HotkeySequence) => {
console.log('Recorded:', sequence)
},
})
return (
<div>
<button
type="button"
onClick={
recorder.isRecording ? recorder.cancelRecording : recorder.startRecording
}
>
{recorder.isRecording
? 'Press chords, then Enter…'
: recorder.recordedSequence
? recorder.recordedSequence.map((h) => formatForDisplay(h)).join(' ')
: 'Click to record'}
</button>
{recorder.isRecording && (
<button type="button" onClick={recorder.cancelRecording}>
Cancel
</button>
)}
</div>
)
}
| Property | Type | Description |
|---|---|---|
| isRecording | boolean | Whether the recorder is listening |
| steps | HotkeySequence | Chords captured in the current session |
| recordedSequence | HotkeySequence | null | Last committed sequence |
| startRecording | () => void | Start a new session |
| stopRecording | () => void | Stop without calling onRecord |
| cancelRecording | () => void | Stop and call onCancel |
| commitRecording | () => void | Commit current steps (no-op if empty) |
Core options live on HotkeySequenceRecorderOptions from @tanstack/hotkeys:
<HotkeysProvider
defaultOptions={{
hotkeySequenceRecorder: {
idleTimeoutMs: 2000,
},
}}
>
<App />
</HotkeysProvider>
| Input | Behavior |
|---|---|
| Valid chord | Appended to steps; listener stays active |
| Enter (no modifiers), commitKeys: 'enter', steps.length >= 1 | Commits and calls onRecord |
| Escape | Cancels; onCancel |
| Backspace / Delete (no modifiers) | Removes last step, or if empty runs onClear + onRecord([]) and stops |
Recorded chords use portable Mod format, same as HotkeyRecorder.
useHotkeySequenceRecorder wraps the HotkeySequenceRecorder class and subscribes to its TanStack Store, same pattern as useHotkeyRecorder.