import { isPrintableKey } from 'ngwr/utils';
// Type-to-search: ignore arrows, Enter and chords.
@HostListener('keydown', ['$event']) onKey(e: KeyboardEvent) {
if (isPrintableKey(e)) buffer.push(e.key);
}isPrintableKey
True for a single printable character typed without Ctrl, Cmd or Alt (Shift is allowed).
Usage
Do not guard with hasModifier first: it counts Shift, so capitals would never arrive.
API
| Name | Description | Type | Default |
|---|---|---|---|
isPrintableKey(event) | True for a single printable character with no Ctrl, Cmd or Alt held. Shift is accepted, so capitals arrive. | (e: KeyboardEvent) => boolean | — |
See also
Guide KeyboardBind shortcuts, show them as keycaps, and see which keys each component handles.Util hasModifierTrue when Ctrl, Cmd, Alt, Shift or Meta is held during a KeyboardEvent.Util KEYSKeyboardEvent.key constants, plus the WrKey union of their values.Util isComposingTrue while an input method (IME) is composing, so the key belongs to it and not to your handler.