Skip to main content
cngx-src documentation

matchesKeyCombo

Functioncore/utils/keyboardv0.1.0

projects/core/utils/keyboard.util.ts

Description#

Tests whether a KeyboardEvent matches a parsed KeyCombo.

A combo matches only a press carrying exactly the modifiers it names: a bare 'b' matches an unmodified b and rejects Cmd+B, Ctrl+B, Shift+B, Alt+B. mod resolves to the platform's primary modifier (Meta on macOS, Ctrl elsewhere) and does not constrain the other one, so 'mod+b' matches Cmd+B on macOS and Ctrl+B elsewhere. A single-character punctuation key is shift-agnostic unless the combo names shift, because the produced character already encodes the shift state (? requires Shift on most layouts): '?' matches the Shift+/ press that yields event.key === '?', while 'shift+?' still requires it and ctrl/meta/alt stay strict for every key.

Events fired during IME composition (event.isComposing) never match - keystrokes that build a composed character are text input, not shortcuts.

Signature#

matchesKeyCombo(event: KeyboardEvent, combo: KeyCombo, isMac: boolean)

Parameters#

@parameventKeyboardEvent

The keyboard event to test.

@paramcomboKeyCombo

The parsed combo to match against.

@paramisMacboolean

Whether the current platform is macOS (affects mod resolution).

Returns#

boolean