A sequence is a hotkey made of chords pressed one after another, like G then H to go home, VS Code's Ctrl+K then Ctrl+C, or Vim commands.
useHotkey and useHotkeys accept sequences just like chords, with the same options, targets, enabled, and meta. This guide covers what's specific to sequences.
Pass an array of chords to useHotkey:
import { useHotkey } from '@tanstack/react-hotkeys'
function App() {
// Press G, then H
useHotkey(['G', 'H'], () => navigate({ to: '/' }))
}Mix chords and sequences freely in useHotkeys:
useHotkeys([
{ hotkey: 'Mod+K', callback: () => openSearch() },
{ hotkey: ['G', 'H'], callback: () => goHome() },
{ hotkey: ['G', 'S'], callback: () => goToSettings() },
])In the callback, context.kind is 'sequence' and context.parsedSequence holds each parsed step:
useHotkey(['Mod+K', 'Mod+C'], (event, context) => {
console.log(context.hotkey) // ['Mod+K', 'Mod+C']
console.log(context.parsedSequence.map((step) => step.key)) // ['K', 'C']
})Every step uses the same chord syntax: strings, physical codes, or RawHotkeyChord objects.
useHotkey(['G', 'H'], () => goHome()) // G then H on any layout
useHotkey(['[KeyG]', '[KeyH]'], () => goHome()) // Physical G and H positions
useHotkey(['Mod+K', 'Mod+C'], () => commentLine()) // Command+K then Command+C on macOS
useHotkey(['G', 'Shift+G'], () => scrollToBottom()) // Separate modifiers per step
useHotkey(['Shift+R', 'Shift+T'], () => runTests()) // Modifiers can stay held between steps
useHotkey([{ key: 'K', mod: true }, 'C'], () => openChat()) // Mix objects and stringsA single-item array like ['Escape'] normalizes to a plain chord 'Escape'. See Write a chord as a string or an object.
Each step must follow the previous one within timeout milliseconds (1000 by default). Set timeout per sequence or globally via HotkeysProvider:
useHotkey(['D', 'D'], () => deleteLine(), { timeout: 500 }) // Snappier double-tap
useHotkey(['G', 'G'], () => scrollToTop(), { timeout: 2000 }) // More forgiving gap<HotkeysProvider defaultOptions={{ hotkey: { timeout: 1500 } }}>
<App />
</HotkeysProvider>While the user types through a sequence:
See Sequences allow 1 second between steps for details.
Most options from Hotkey options behave identically, with a few sequence-specific details:
| Pattern | Example | Behavior |
|---|---|---|
| Shared prefix | ['D', 'D'] and ['D', 'W'] | Both track progress independently until the next key decides (no warning) |
| Prefix of a longer sequence | ['G', 'G'] and ['G', 'G', 'G'] | Shorter fires immediately on step 2, and longer fires on step 3 |
| Chord and sequence on same key | 'G' and ['G', 'G'] | First G fires the chord. Once a sequence is active, continuing keys belong to it |
useHotkeys([
{ hotkey: ['D', 'D'], callback: () => deleteLine() },
{ hotkey: ['D', 'W'], callback: () => deleteWord() },
{ hotkey: ['D', 'I', 'W'], callback: () => deleteInnerWord() },
])Sharing leading steps is expected and never triggers a duplicate warning. Two sequences are duplicates only if all steps match. See Handle duplicate hotkeys.
If one sequence is a strict prefix of another, such as ['G', 'G'] and ['G', 'G', 'G'], the shorter sequence fires immediately on the second G without waiting to see if a third follows. The third G fires ['G', 'G', 'G'], and a fourth fires ['G', 'G'] again.
Prefer non-overlapping sequences such as ['G', 'G'] and ['G', 'B']. App Hotkeys and Hotkey Recording (detectConflicts) treat prefix overlaps as conflicts.
Once a sequence is underway, a key that continues it belongs to the sequence and blocks any standalone chord on that key:
useHotkeys([
{ hotkey: 'C', callback: () => compose() }, // Standalone C
{ hotkey: ['G', 'C'], callback: () => goToContacts() }, // Pressing G then C won't trigger compose()
])By contrast, the first step doesn't block a chord on the same key because the user might just want the single key:
useHotkeys([
{ hotkey: 'G', callback: () => openGoMenu() }, // Runs on first G
{ hotkey: ['G', 'G'], callback: () => scrollToTop() }, // Runs on second G
])Timed-out, disabled, or input-ignored sequences never claim keys. Note that App Hotkeys and Hotkey Recording check conflicts more strictly and flag G versus ['G', 'H'] as colliding.
useFormatForDisplay formats each step and joins them with spaces by default, customizable via sequenceSeparator:
formatForDisplay(['Mod+K', 'Mod+C'], { platform: 'mac' }) // '⌘ K ⌘ C'
formatForDisplay(['G', 'H'], { sequenceSeparator: ' then ' }) // 'G then H'See Formatting & Display for keycaps and layout options.
Because the first key of a sequence has no immediate effect, showing pending keys in a status banner (like VS Code after Ctrl+K) makes sequences discoverable. Read matchedStepCount from useHotkeyRegistrations:
import {
useFormatForDisplay,
useHotkeyRegistrations,
} from '@tanstack/react-hotkeys'
import type { HotkeySequenceRegistrationView } from '@tanstack/react-hotkeys'
function PendingKeys() {
const formatForDisplay = useFormatForDisplay()
const inProgress = useHotkeyRegistrations().filter(
(reg): reg is HotkeySequenceRegistrationView =>
reg.kind === 'sequence' && reg.matchedStepCount > 0,
)
const longest = inProgress.sort(
(a, b) => b.matchedStepCount - a.matchedStepCount,
)[0]
if (!longest) return null
const pressed = longest.hotkey.slice(0, longest.matchedStepCount)
return (
<p role="status">
<kbd>{formatForDisplay(pressed)}</kbd> was pressed. Waiting for the next
key.
</p>
)
}matchedStepCount resets automatically on completion, mismatch, or timeout, so the status clears itself. See Cheat Sheets for displaying full shortcut lists.
A sequence made only of letters, numbers, or symbols (like ['G', 'H']) is treated as a character-key shortcut under accessibility guidelines. Give users a way to turn it off via enabled or remap it with App Hotkeys. See Single-key shortcuts need an off switch.
function VimNavigation() {
useHotkeys([
{ hotkey: ['G', 'G'], callback: () => scrollToTop() },
{ hotkey: ['G', 'Shift+G'], callback: () => scrollToBottom() },
{ hotkey: ['D', 'D'], callback: () => deleteLine() },
{ hotkey: ['D', 'W'], callback: () => deleteWord() },
{ hotkey: ['C', 'I', 'W'], callback: () => changeInnerWord() },
])
}useHotkey(
[
'ArrowUp', 'ArrowUp',
'ArrowDown', 'ArrowDown',
'ArrowLeft', 'ArrowRight',
'ArrowLeft', 'ArrowRight',
'B', 'A',
],
() => enableEasterEgg(),
{ timeout: 2000 },
)To let users record sequences in settings, see Hotkey Recording. To match sequences outside the hotkey manager, see Match a sequence on your own.
Note
useHotkeySequence, useHotkeySequences, and useHotkeySequenceRecorder were removed in @tanstack/react-hotkeys v0.14.0. Pass sequence arrays directly to useHotkey or useHotkeys, and pass maxSteps: Infinity to useHotkeyRecorder.