# HotkeyController

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

Defined in: [controllers/hotkey.ts:73](https://github.com/TanStack/hotkeys/blob/main/packages/lit-hotkeys/src/controllers/hotkey.ts#L73)

A Lit ReactiveController that registers a hotkey when the host element is
connected and unregisters it when the host is disconnected. The hotkey can
be a chord such as `'Mod+S'`, a sequence such as `['G', 'G']`, or an app
hotkey from `defineAppHotkeys`, which uses its custom hotkey from
`provideAppHotkeys`.

Chords accept `requireReset`; sequences accept `timeout`. Pass a getter for
the hotkey or options to re-read them after each host update.

## Example

```ts
class MyElement extends LitElement {
  private save = new HotkeyController(this, 'Mod+S', () => this.doSave())
  private top = new HotkeyController(this, ['G', 'G'], () => this.scrollToTop())
}
```

## Implements

- `ReactiveController`

## Constructors

### Constructor

```ts
new HotkeyController(
   host, 
   hotkey, 
   callback, 
   options?
): HotkeyController;
```

Defined in: [controllers/hotkey.ts:85](https://github.com/TanStack/hotkeys/blob/main/packages/lit-hotkeys/src/controllers/hotkey.ts#L85)

#### Parameters

##### host

`ReactiveControllerHost`

The Lit component that owns this controller. The controller adds itself to it.

##### hotkey

`MaybeGetter`\<
  \| `AppHotkey`\<`string`, `HotkeyChord` \| `HotkeySequence` \| `null`\>
  \| `null`
  \| `undefined`\>

The chord, sequence, or app hotkey to register, or a getter. A getter is read on connection and after host updates. `undefined`, `null`, or `''` registers nothing, for an optional shortcut.

##### callback

`HotkeyCallback`

Called with the host as `this`.

##### options?

`MaybeGetter`\<[`AppHotkeyControllerOptions`](../type-aliases/AppHotkeyControllerOptions.md)\<`AppHotkey`\<`string`, HotkeyChord \| HotkeySequence \| null\>\>\>

Options or a getter. Property getters are read on connection and after host updates.

#### Returns

`HotkeyController`

### Constructor

```ts
new HotkeyController(
   host, 
   hotkey, 
   callback, 
   options?
): HotkeyController;
```

Defined in: [controllers/hotkey.ts:91](https://github.com/TanStack/hotkeys/blob/main/packages/lit-hotkeys/src/controllers/hotkey.ts#L91)

#### Parameters

##### host

`ReactiveControllerHost`

##### hotkey

`MaybeGetter`\<`RegisterableHotkey` \| `null` \| `undefined`\>

##### callback

`HotkeyCallback`

##### options?

`MaybeGetter`\<[`HotkeyControllerCommonOptions`](../type-aliases/HotkeyControllerCommonOptions.md)\>

#### Returns

`HotkeyController`

## Methods

### dispose()

```ts
dispose(): void;
```

Defined in: [controllers/hotkey.ts:160](https://github.com/TanStack/hotkeys/blob/main/packages/lit-hotkeys/src/controllers/hotkey.ts#L160)

Releases the controller now and removes it from its host. Use it to
remove a controller early: Lit's `removeController` alone leaves it active.

#### Returns

`void`

***

### hostConnected()

```ts
hostConnected(): void;
```

Defined in: [controllers/hotkey.ts:110](https://github.com/TanStack/hotkeys/blob/main/packages/lit-hotkeys/src/controllers/hotkey.ts#L110)

Registers when connected and a target is available.

#### Returns

`void`

#### Implementation of

```ts
ReactiveController.hostConnected
```

***

### hostDisconnected()

```ts
hostDisconnected(): void;
```

Defined in: [controllers/hotkey.ts:149](https://github.com/TanStack/hotkeys/blob/main/packages/lit-hotkeys/src/controllers/hotkey.ts#L149)

Releases registrations when the host disconnects.

#### Returns

`void`

#### Implementation of

```ts
ReactiveController.hostDisconnected
```

***

### hostUpdated()

```ts
hostUpdated(): void;
```

Defined in: [controllers/hotkey.ts:120](https://github.com/TanStack/hotkeys/blob/main/packages/lit-hotkeys/src/controllers/hotkey.ts#L120)

Refreshes options after rendering, when scoped targets are available.

#### Returns

`void`

#### Implementation of

```ts
ReactiveController.hostUpdated
```
