# injectHotkey

<!-- DO NOT EDIT: this page is autogenerated from the type comments -->

```ts
function injectHotkey<T>(
   hotkey, 
   callback, 
   options?
): void;
```

Defined in: [injectHotkey.ts:81](https://github.com/TanStack/hotkeys/blob/main/packages/angular-hotkeys/src/injectHotkey.ts#L81)

Angular inject-based API for registering a hotkey: a chord such as
`'Mod+S'`, a sequence such as `['G', 'G']`, or an app hotkey from
`defineAppHotkeys`. The hotkey and options may be getters that read signals.

Chords accept `requireReset`; sequences accept `timeout`. A one-step
sequence registers as its chord. An app hotkey uses its effective hotkey
from `provideHotkeys` (including the user's custom hotkey) and its declared
meta and options, and registers nothing while unbound. A hotkey of
`undefined`, `null`, or `''` registers nothing, for an optional shortcut
such as `() => this.shortcut()`; when it changes to a hotkey, it registers.

## Type Parameters

### T

`T` *extends* `AdapterHotkeyInput`

## Parameters

### hotkey

`IfTypeParameter`\<`T`, `MaybeGetter`\<`T` \| `null` \| `undefined`\>, `KnownHotkey`\<`T`, `MaybeGetter`\<`T` \| `null` \| `undefined`\>\>\>

### callback

`HotkeyCallback`\<`IfTypeParameter`\<`T`, `HotkeyCallbackContext`, `AdapterCallbackContextFor`\<`T`\>\>\>

### options?

`IfTypeParameter`\<`T`, `MaybeGetter`\<[`InjectHotkeyOptions`](../type-aliases/InjectHotkeyOptions.md)\>, `MaybeGetter`\<\[`T`\] *extends* \[`AppHotkey`\<`string`, `AppHotkeyBinding`\>\] ? `AdapterAppHotkeyOptions`\<`Extract`\<`T`, `AppHotkey`\<`string`, `AppHotkeyBinding`\>\>, [`InjectHotkeyTarget`](../type-aliases/InjectHotkeyTarget.md)\> : `AdapterOptionsFor`\<`T`, [`InjectHotkeyTarget`](../type-aliases/InjectHotkeyTarget.md)\>\>\>

## Returns

`void`

## Example

```ts
@Component({ ... })
export class EditorComponent {
  constructor() {
    injectHotkey('Mod+S', () => this.save())
    injectHotkey(['G', 'G'], () => this.scrollToTop(), { timeout: 500 })
    injectHotkey('Escape', () => this.close(), () => ({ enabled: this.isOpen() }))
  }
}
```
