# hotkey

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

```ts
function hotkey<T>(hotkey, options?): HotkeyDecorator<IfTypeParameter<T, HotkeyCallbackContext, AdapterCallbackContextFor<T>>>;
```

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

Decorator that registers a hotkey on the element when it connects and
unregisters when it disconnects: a chord such as `'Mod+S'`, a sequence such
as `['G', 'G']`, or an app hotkey. Uses [HotkeyController](../classes/HotkeyController.md) under the hood.

Works with legacy (`experimentalDecorators`) and standard decorators. The
method is looked up when the hotkey fires, so subclass overrides run. A
subclass that decorates an override replaces the parent's hotkeys for that
method; an override without `@hotkey` keeps them.

## Type Parameters

### T

`T` *extends* `AdapterHotkeyInput`

## Parameters

### hotkey

`IfTypeParameter`\<`T`, `AdapterWrapperHotkey`, `KnownHotkey`\<`T`\>\>

The chord, sequence, or app hotkey to listen for.

### options?

`IfTypeParameter`\<`T`, [`HotkeyControllerOptions`](../type-aliases/HotkeyControllerOptions.md), \[`T`\] *extends* \[`AppHotkey`\<`string`, `AppHotkeyBinding`\>\] ? [`AppHotkeyControllerOptions`](../type-aliases/AppHotkeyControllerOptions.md)\<`Extract`\<`T`, `AppHotkey`\<`string`, `AppHotkeyBinding`\>\>\> : [`HotkeyControllerOptionsFor`](../type-aliases/HotkeyControllerOptionsFor.md)\<`T`\>\>

Optional registration options (target, platform, enabled, etc.).

## Returns

[`HotkeyDecorator`](../type-aliases/HotkeyDecorator.md)\<`IfTypeParameter`\<`T`, `HotkeyCallbackContext`, `AdapterCallbackContextFor`\<`T`\>\>\>

A method decorator for use on Lit element methods.

## Example

```ts
class MyElement extends LitElement {
  @hotkey('Mod+S')
  save() { this.doSave() }

  @hotkey(['G', 'G'], { timeout: 500 })
  goToTop() { window.scrollTo(0, 0) }
}
```
