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
API Reference
Hotkeys API Reference
Hotkey Sequence API Reference
Key Hold API Reference
Held Keys API Reference
Hotkey Recorder API Reference
Hotkey Sequence Recorder API Reference
Format for Display API Reference

createHotkeyHandler

Function: createHotkeyHandler()

ts
function createHotkeyHandler(
   hotkey, 
   callback, 
   options): (event) => void;

Defined in: match.ts:159

Creates a keyboard event handler that calls the callback when the hotkey matches.

Parameters

hotkey

The hotkey string or ParsedHotkey to match

Hotkey | ParsedHotkey

callback

HotkeyCallback

The function to call when the hotkey matches

options

CreateHotkeyHandlerOptions = {}

Options for matching and handling

Returns

A function that can be used as an event handler

ts
(event): void;

Parameters

event

KeyboardEvent

Returns

void

Example

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

document.addEventListener('keydown', handler)