# createHotkeyAttachment

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

```ts
function createHotkeyAttachment<T>(
   hotkey, 
   callback, 
   options?
): Attachment<HTMLElement>;
```

Defined in: [packages/svelte-hotkeys/src/createHotkey.svelte.ts:111](https://github.com/TanStack/hotkeys/blob/main/packages/svelte-hotkeys/src/createHotkey.svelte.ts#L111)

Create an attachment for an element-scoped hotkey: a chord, a sequence, or
an app hotkey that listens on the attached element. `undefined`, `null`,
or `''` registers nothing, for an optional shortcut.

## 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`\<[`CreateHotkeyOptions`](../type-aliases/CreateHotkeyOptions.md)\>, `MaybeGetter`\<\[`T`\] *extends* \[`AppHotkey`\<`string`, `AppHotkeyBinding`\>\] ? `AdapterAppHotkeyOptions`\<`Extract`\<`T`, `AppHotkey`\<`string`, `AppHotkeyBinding`\>\>, [`CreateHotkeyTarget`](../type-aliases/CreateHotkeyTarget.md)\> : `AdapterOptionsFor`\<`T`, [`CreateHotkeyTarget`](../type-aliases/CreateHotkeyTarget.md)\>\>\>

## Returns

`Attachment`\<`HTMLElement`\>

## Example

```svelte
<script lang="ts">
  const saveKey = createHotkeyAttachment('Mod+S', () => save())
</script>

<div tabindex="0" {@attach saveKey}>Editor content</div>
```
