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

keyboardEventToHotkey

Function: keyboardEventToHotkey()

ts
function keyboardEventToHotkey(event): Hotkey;

Defined in: parse.ts:248

Converts a KeyboardEvent directly to a hotkey string.

This is a convenience function that combines parseKeyboardEvent() and formatting. The resulting hotkey string uses canonical modifier names (Control, Alt, Shift, Meta) and is suitable for use with useHotkey() and other hotkey functions.

Parameters

event

KeyboardEvent

The KeyboardEvent to convert

Returns

Hotkey

A hotkey string in canonical form (e.g., 'Control+Shift+S')

Example

ts
document.addEventListener('keydown', (event) => {
  const hotkey = keyboardEventToHotkey(event)
  console.log(hotkey) // 'Control+Shift+S'
  useHotkey(hotkey, () => console.log('Shortcut triggered'))
})