UtilOptional

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.

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);
}

API

NameDescriptionTypeDefault
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