UtilOptional

hasModifier

True when Ctrl, Cmd, Alt, Shift or Meta is held during a KeyboardEvent.

Usage

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

API

NameDescriptionTypeDefault
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