import { hasModifier } from 'ngwr/utils';
@HostListener('keydown', ['$event']) onKey(e: KeyboardEvent) {
if (hasModifier(e)) return; // let chords such as Cmd+K through
if (e.key === 'k') focusSearch();
}hasModifier
True when Ctrl, Cmd, Alt, Shift or Meta is held during a KeyboardEvent.
Usage
API
| Name | Description | Type | Default |
|---|---|---|---|
hasModifier(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 isPrintableKeyTrue for a single printable character typed without Ctrl, Cmd or Alt (Shift is allowed).Util KEYSKeyboardEvent.key constants, plus the WrKey union of their values.Service WrHotkeyRegister keyboard shortcuts like mod+k, where mod is ⌘ on macOS and Ctrl elsewhere.Util isComposingTrue while an input method (IME) is composing, so the key belongs to it and not to your handler.