Hotkey strings type-check against the keys of a US QWERTY keyboard, so createHotkey('Mod+Ö', toggleComment) is a type error. The hotkey itself works: it fires when a German user presses Ctrl+Ö or Command+Ö. Only TypeScript rejects it. Registering the layouts your app targets makes TypeScript accept their keys.
Registering a layout changes types only. It doesn't change how hotkeys match, and it adds no code to your bundle. Most apps don't need it. Use it when your app targets users of specific layouts and you want shortcuts on keys only those layouts have.
A hotkey on a key that only one layout types fires only for users of that layout. US users can't press Mod+Ö. For a shortcut every user should have, bind A to Z or 0 to 9 instead. TanStack Hotkeys matches these on other layouts, and many US punctuation keys too:
Register a layout when the key itself matters, such as a single-key ß shortcut, or a shortcut that your German interface labels with Ö.
Augment Register with keys, a union of the sets your app targets. Each set is a type exported from @tanstack/svelte-hotkeys:
import type { GermanKeys, UsKeys } from '@tanstack/svelte-hotkeys'
declare module '@tanstack/svelte-hotkeys' {
interface Register {
keys: UsKeys | GermanKeys
}
}Put this in a .ts file of your TypeScript project, such as src/main.ts, where you mount your app. In SvelteKit, src/app.d.ts works too. Run svelte-check to check the hotkeys in your components, because tsc alone doesn't read .svelte files. If you also register app hotkeys, add keys to the same Register interface, or declare it in another file. TypeScript merges the two.
German keys now type-check wherever a hotkey goes:
createHotkey('Mod+Ö', toggleComment)
createHotkey('ß', toggleSidebar)
createHotkey('Mod+[', outdent) // Still accepted, because UsKeys is listed
createHotkey('Mod+Ñ', search) // Type error: Spanish isn't registeredcreateHotkeys, createHotkeyAttachment, createHotkeysAttachment, getHotkeyHint, getFormatForDisplay, app hotkeys, custom hotkeys, and the Hotkey and HotkeyChord types all follow the registration.
There are 26 sets, which cover 33 layouts, such as UkKeys, FrenchKeys, SwedishKeys, and RussianKeys. Layouts that type the same keys share a set under two names, such as AustrianKeys and GermanKeys. Sensible Defaults lists every set and how each one is built.
The Keyboard Layouts example registers German keys and shows which hotkeys fire on a German keyboard.