# HotkeyRecorderController

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

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

A Lit ReactiveController that records keyboard shortcuts.

With the default `maxSteps: 1`, the first valid chord is recorded. With a
larger `maxSteps`, each chord adds a step; the recording commits on Enter
(unless `commitKeys: 'none'`), after `idleTimeoutMs`, or at `maxSteps`, and
`onRecord` receives a chord (one step) or a sequence. Escape cancels, and
so do Tab and Shift+Tab unless `recordTab` is set; Backspace/Delete removes
the last step or clears.

## Example

```ts
class ShortcutSettings extends LitElement {
  private recorder = new HotkeyRecorderController(this, {
    onRecord: (hotkey) => {
      this.shortcut = hotkey
      this.requestUpdate()
    },
    onCancel: () => {
      console.log('Recording cancelled')
    },
  })

  private shortcut: Hotkey | null = null

  render() {
    return html`
      <button @click=${() => this.recorder.startRecording()}>
        ${this.recorder.isRecording ? 'Recording...' : 'Edit Shortcut'}
      </button>
      ${this.recorder.recordedHotkey
        ? html`<div>Recording: ${this.recorder.recordedHotkey}</div>`
        : nothing}
    `
  }
}
```

## Implements

- `ReactiveController`
- `HotkeyRecorderState`
- `HotkeyRecorderActions`

## Constructors

### Constructor

```ts
new HotkeyRecorderController(host, options): HotkeyRecorderController;
```

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

#### Parameters

##### host

`ReactiveControllerHost`

The Lit component that owns this controller.

##### options

`HotkeyChordRecorderOptions`

Options or a getter, read during recording.

#### Returns

`HotkeyRecorderController`

### Constructor

```ts
new HotkeyRecorderController(host, options): HotkeyRecorderController;
```

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

#### Parameters

##### host

`ReactiveControllerHost`

##### options

`HotkeySequenceRecorderOptions`

#### Returns

`HotkeyRecorderController`

### Constructor

```ts
new HotkeyRecorderController(host, options): HotkeyRecorderController;
```

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

#### Parameters

##### host

`ReactiveControllerHost`

##### options

() => `HotkeySequenceRecorderOptions`

#### Returns

`HotkeyRecorderController`

### Constructor

```ts
new HotkeyRecorderController(host, options): HotkeyRecorderController;
```

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

#### Parameters

##### host

`ReactiveControllerHost`

##### options

() => `HotkeyChordRecorderOptions`

#### Returns

`HotkeyRecorderController`

### Constructor

```ts
new HotkeyRecorderController(host, options): HotkeyRecorderController;
```

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

#### Parameters

##### host

`ReactiveControllerHost`

##### options

() => `HotkeyRecorderOptions`

#### Returns

`HotkeyRecorderController`

## Accessors

### isRecording

#### Get Signature

```ts
get isRecording(): boolean;
```

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

Whether recording is currently active.

##### Returns

`boolean`

#### Implementation of

```ts
HotkeyRecorderState.isRecording
```

***

### recordedHotkey

#### Get Signature

```ts
get recordedHotkey(): Hotkey | null;
```

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

The last committed hotkey: a chord, or a sequence of two or more steps.

##### Returns

`Hotkey` \| `null`

#### Implementation of

```ts
HotkeyRecorderState.recordedHotkey
```

***

### steps

#### Get Signature

```ts
get steps(): HotkeySequence;
```

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

Chords recorded so far in a multi-step recording (for live preview).

##### Returns

`HotkeySequence`

#### Implementation of

```ts
HotkeyRecorderState.steps
```

## Methods

### cancelRecording()

```ts
cancelRecording(): void;
```

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

Cancel recording without saving.

#### Returns

`void`

#### Implementation of

```ts
HotkeyRecorderActions.cancelRecording
```

***

### commitRecording()

```ts
commitRecording(): void;
```

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

Commit the recorded steps now (multi-step recordings).

#### Returns

`void`

#### Implementation of

```ts
HotkeyRecorderActions.commitRecording
```

***

### dispose()

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

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

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-recorder.ts:124](https://github.com/TanStack/hotkeys/blob/main/packages/lit-hotkeys/src/controllers/hotkey-recorder.ts#L124)

Subscribes to the recorder store and updates the internal state when changes occur.

#### Returns

`void`

#### Implementation of

```ts
ReactiveController.hostConnected
```

***

### hostDisconnected()

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

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

Unsubscribes from the recorder store and destroys the recorder instance to prevent memory leaks.

#### Returns

`void`

#### Implementation of

```ts
ReactiveController.hostDisconnected
```

***

### setOptions()

```ts
setOptions(options): void;
```

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

Updates the recorder options (e.g. callbacks).

#### Parameters

##### options

`Partial`\<`HotkeyRecorderOptions`\>

#### Returns

`void`

***

### startRecording()

```ts
startRecording(): void;
```

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

Start recording a new hotkey.

#### Returns

`void`

#### Implementation of

```ts
HotkeyRecorderActions.startRecording
```

***

### stopRecording()

```ts
stopRecording(): void;
```

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

Stop recording (same as cancel but without calling onCancel).

#### Returns

`void`

#### Implementation of

```ts
HotkeyRecorderActions.stopRecording
```
