Skip to content

Latest commit

 

History

History
42 lines (28 loc) · 976 Bytes

File metadata and controls

42 lines (28 loc) · 976 Bytes
id keyboardEventToHotkey
title keyboardEventToHotkey

Function: keyboardEventToHotkey()

function keyboardEventToHotkey(event): Hotkey;

Defined in: parse.ts:256

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

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