Docs
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
OpenRouter
Neon
WorkOS
Clerk
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
OpenRouter
Neon
WorkOS
Clerk
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
Hotkeys API Reference
App Hotkeys API Reference
Key hold & held keys API Reference
Hotkey Recorder API Reference
Normalization & format API Reference

createHotkeyChordHandler

ts
function createHotkeyChordHandler(
   chord, 
   callback, 
   options?): (event) => void;
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)
const handler = createHotkeyChordHandler('Mod+S', (event, { hotkey, parsedChord }) => {
  console.log(`${hotkey} was pressed`)
  handleSave()
})

document.addEventListener('keydown', handler)