Skip to content
Source
Sign inSign up
TanStack/hotkeys
Open History to see the last commit

parseKeyboardEvent.md

42 lines871 Bytes

function parseKeyboardEvent(event, platform?): ParsedHotkeyChord;

Defined in: parse.ts:308

Parses a KeyboardEvent into the chord it pressed, in the same format as parseHotkey(). Pass the result to normalizeHotkey for its canonical string.

Parameters

event

KeyboardEvent

The KeyboardEvent to parse

platform?

Platform

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

Returns

ParsedHotkeyChord

The parsed chord for the keyboard event

Example

document.addEventListener('keydown', (event) => {
  const parsed = parseKeyboardEvent(event)
  console.log(parsed) // { key: 'S', ctrl: true, shift: false, ... }
})