# defineHotkey

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

```ts
function defineHotkey<T>(definition): Readonly<CreateHotkeyDefinition>;
```

Defined in: [packages/svelte-hotkeys/src/createHotkeys.svelte.ts:102](https://github.com/TanStack/hotkeys/blob/main/packages/svelte-hotkeys/src/createHotkeys.svelte.ts#L102)

Checks one hotkey for `createHotkeys` as `createHotkey` checks its arguments, and
returns it unchanged. In an array, a hotkey object is checked only when it
is written inline, and it takes the options of both kinds. Here the hotkey
can be a variable, a key no hotkey object has is a type error, and the
callback context and the options follow the kind of the hotkey.
The hotkey and the options may be getters.

## Type Parameters

### T

`T` *extends* `AdapterHotkeyInput`

## Parameters

### definition

#### callback

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

The function to call when the hotkey is pressed

#### hotkey

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

A chord, a sequence, a hotkey object, or an app hotkey

#### options?

`IfTypeParameter`\<`T`, `MaybeGetter`\<[`CreateHotkeyOptions`](../type-aliases/CreateHotkeyOptions.md)\>, `MaybeGetter`\<\[`T`\] *extends* \[`AppHotkey`\<`string`, `AppHotkeyBinding`\>\] ? [`CreateAppHotkeyOptions`](../type-aliases/CreateAppHotkeyOptions.md)\<`Extract`\<`T`, `AppHotkey`\<`string`, `AppHotkeyBinding`\>\>\> : [`CreateHotkeyOptionsFor`](../type-aliases/CreateHotkeyOptionsFor.md)\<`T`\>\>\>

Per-hotkey options (merged on top of commonOptions)

## Returns

`Readonly`\<[`CreateHotkeyDefinition`](../type-aliases/CreateHotkeyDefinition.md)\>

## Example

```ts
const play = defineHotkey({
  hotkey: { default: 'Space', alternates: ['K'] },
  callback: () => togglePlay(),
  options: { requireReset: true },
})

createHotkeys([play])
```
