Skip to main content

Function: comboFromEvent()

comboFromEvent(event, platform?): KeyCombo | undefined

Defined in: src/lib/utils/shortcuts/index.ts:516

The key combination of a key press, matching keyboards with different layouts:

  • Keys are matched by the character they type, so letters follow the key's label (e.g. a on a French keyboard).
  • Digits and symbols ignore Shift and AltGr/Option, which are often needed to type them (e.g. < and [ on a German keyboard).
  • When a key types a character that isn't basic Latin (another alphabet, or Option on macOS), or is a dead key, the physical key is used instead (e.g. a for ф, and alt g for Option+G typing ©).
  • = counts as +, so cmd + works with or without Shift.

cmd is Command on Apple devices and Ctrl elsewhere; ctrl is Control on Apple devices. Undefined while composing text (e.g. with an input method), for modifier keys alone, and for the Windows key elsewhere.

Parameters​

event​

KeyEventLike

platform?​

string

Returns​

KeyCombo | undefined

Example​

comboFromEvent({ key: "Z", metaKey: true, ctrlKey: false, shiftKey: true, altKey: false }, "MacIntel");
// { key: "z", cmd: true, shift: true }