TanStack

createHotkeyChordHandler

ts
function createHotkeyChordHandler(
   chord, 
   callback, 
   options?): (event) => void;

Defined in: match.ts:91

Creates a keyboard event handler that calls the callback when the chord matches. For sequences, use createSequenceMatcher.

Parameters

chord

| HotkeyChord | ParsedHotkeyChord

The chord string or parsed chord to match

callback

HotkeyCallback<HotkeyChordCallbackContext>

The function to call when the hotkey matches

options?

CreateHotkeyChordHandlerOptions = {}

Options for matching and handling

Returns

A function that can be used as an event handler

(event) => void

Example

ts
const handler = createHotkeyChordHandler('Mod+S', (event, { hotkey, parsedChord }) => {
  console.log(`${hotkey} was pressed`)
  handleSave()
})

document.addEventListener('keydown', handler)