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

matchesKeyboardEvent

Function: matchesKeyboardEvent()

ts
function matchesKeyboardEvent(
   event, 
   hotkey, 
   platform): boolean;

Defined in: match.ts:43

Checks if a KeyboardEvent matches a hotkey.

Uses the key property from KeyboardEvent for matching, with a fallback to code for letter keys, digit keys (0-9), and punctuation keys when key produces special characters (e.g., macOS Option+letter, Shift+number, or Option+punctuation). Letter keys are matched case-insensitively.

Also handles "dead key" events where event.key is 'Dead' instead of the expected character. This commonly occurs on macOS with Option+letter combinations (e.g., Option+E, Option+I, Option+U, Option+N) and on Windows/Linux with international keyboard layouts. In these cases, event.code is used to determine the physical key.

Parameters

event

KeyboardEvent

The KeyboardEvent to check

hotkey

The hotkey string or ParsedHotkey to match against

Hotkey | ParsedHotkey

platform

The target platform for resolving 'Mod' (defaults to auto-detection)

"mac" | "windows" | "linux"

Returns

boolean

True if the event matches the hotkey

Example

ts
document.addEventListener('keydown', (event) => {
  if (matchesKeyboardEvent(event, 'Mod+S')) {
    event.preventDefault()
    handleSave()
  }
})