# hasModifier

> Tiny predicate that reports whether any modifier key (Ctrl, Cmd, Alt, Shift, Meta) is held on a `KeyboardEvent` — handy for letting OS-level chords pass through your keydown handlers.

Source: https://ngwr.dev/reference/utils/has-modifier  
Kind: Util

## Usage

```angular-ts
import { hasModifier } from 'ngwr/utils';

@HostListener('keydown', ['$event']) onKey(e: KeyboardEvent) {
  if (hasModifier(e)) return;   // let Ctrl/Cmd-+key shortcuts through
  if (e.key === 'k') focusSearch();
}
```

## Why ngwr provides this

Almost every single-key shortcut (J/K nav, slash-to-search, type-to-jump) needs to back off when a chord is being typed — otherwise Cmd+K hits both the OS shortcut AND your handler. Spelling out `e.ctrlKey || e.metaKey || e.altKey || e.shiftKey` everywhere is noise; the helper makes the intent obvious.

```angular-ts
// Native — boilerplate, repeats across handlers.
@HostListener('keydown', ['$event']) onKey(e: KeyboardEvent) {
  if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey) return;
  if (e.key === 'k') focusSearch();
}

// ngwr — one call, OS-agnostic.
@HostListener('keydown', ['$event']) onKey(e: KeyboardEvent) {
  if (hasModifier(e)) return;
  if (e.key === 'k') focusSearch();
}
```

## API

| Name | Description | Type | Default |
| --- | --- | --- | --- |
| `hasModifier(event)` | True when Ctrl / Cmd / Alt / Shift / Meta is currently held. Use to bypass plain-key shortcuts during chorded shortcuts. | `(e: KeyboardEvent) => boolean` | `—` |

## See also

- [Keyboard](https://ngwr.dev/guides/keyboard) — How chords, keycaps and key primitives fit together in one task.
- [isPrintableKey](https://ngwr.dev/reference/utils/is-printable-key) — The other half of a type-ahead guard.
- [KEYS](https://ngwr.dev/reference/utils/keys) — Canonical `KeyboardEvent.key` constants.
