import { wrHasModifier } from 'ngwr/utils';
@HostListener('keydown', ['$event']) onKey(e: KeyboardEvent) {
if (wrHasModifier(e)) return; // let chords such as Cmd+K through
if (e.key === 'k') focusSearch();
}wrHasModifier
True when Ctrl, Cmd, Alt, Shift or Meta is held during a KeyboardEvent.
Usage
API
| Name | Description | Type | Default |
|---|---|---|---|
wrHasModifier(event) | True when Ctrl, Cmd, Alt, Shift or Meta is held. Return early on it in single-key shortcuts. | (e: KeyboardEvent) => boolean | — |
See also
Guide KeyboardBind shortcuts, show them as keycaps, and see which keys each component handles.Util wrIsPrintableKeyTrue for a single printable character typed without Ctrl, Cmd or Alt (Shift is allowed).Util WR_KEYSKeyboardEvent.key constants, the WrKey union of their values, and WR_KEY_LABELS, what each key is called on a keycap.Service WrHotkeyRegister keyboard shortcuts like mod+k, where mod is ⌘ on macOS and Ctrl elsewhere.Util wrIsComposingTrue while an input method (IME) is composing, so the key belongs to it and not to your handler.