Docs
CodeRabbit
Cloudflare
Railway
OpenRouter
SerpAPI
Netlify
Clerk
AG Grid
WorkOS
Sentry
Prisma
Unkey
Electric
CodeRabbit
Cloudflare
Railway
OpenRouter
SerpAPI
Netlify
Clerk
AG Grid
WorkOS
Sentry
Prisma
Unkey
Electric
API Reference
Hotkeys API Reference
Hotkey Sequence API Reference
Key hold & held keys API Reference
Hotkey Recorder API Reference
Hotkey Sequence Recorder API Reference
Normalization & format API Reference
Hotkeys API Reference

createHotkey

Function: createHotkey()

ts
function createHotkey(
   hotkey, 
   callback, 
   options): void;
function createHotkey(
   hotkey, 
   callback, 
   options): void;

Defined in: packages/svelte-hotkeys/src/createHotkey.svelte.ts:56

Register a global hotkey for the current component.

Parameters

hotkey

MaybeGetter<RegisterableHotkey>

callback

HotkeyCallback

options

MaybeGetter<CreateHotkeyOptions> = {}

Returns

void

Example

svelte
<script lang="ts">
  import { createHotkey } from '@tanstack/svelte-hotkeys'

  createHotkey('Mod+S', () => {
    console.log('Mod+S pressed')
  })
</script>
<script lang="ts">
  import { createHotkey } from '@tanstack/svelte-hotkeys'

  createHotkey('Mod+S', () => {
    console.log('Mod+S pressed')
  })
</script>