Skip to content
Advanced & Integration

Type Keys from Other Keyboard Layouts in Angular

By default, hotkey strings type-check against US QWERTY keys, so injectHotkey('Mod+Ö', () => this.toggleComment()) triggers a TypeScript error. At runtime, it already works when a German user presses Ctrl+Ö or Cmd+Ö.

Registering extra keyboard layout sets tells TypeScript to accept those characters too. It changes types only, adds zero runtime code to your bundle, and doesn't alter how keys match.

Prefer keys every layout has

Most apps never need to register extra layouts. A to Z, 0 to 9, and common US punctuation already match across international layouts automatically:

  • Mod+S matches on a Russian keyboard, where that key types ы.
  • Mod+; matches on German Ctrl+Ö and Spanish Ctrl+Ñ in the same physical slot.
  • On Greek, Cyrillic, and Hebrew layouts, prefer Mod+A over Mod+Ф. It matches on the same key and keeps working if the user toggles back to Latin.
  • Punctuation that another layout types with Shift, such as / on German QWERTZ, can't match with Command held on macOS. See Keys match the character the user types for why and how to add the shifted fallback.

Register layout sets only when you intentionally target keys unique to specific layouts, such as a single-key ß shortcut or shortcuts labeled with Ö in a localized UI.

Register layouts

Augment Register with keys, a union of the layout types your app supports. Each set is a type exported from @tanstack/angular-hotkeys:

ts
import type { GermanKeys, UsKeys } from '@tanstack/angular-hotkeys'

declare module '@tanstack/angular-hotkeys' {
  interface Register {
    keys: UsKeys | GermanKeys
  }
}

Place this declaration in any file of your TypeScript project, such as main.ts, where you bootstrap your app. 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:

ts
injectHotkey('Mod+Ö', () => this.toggleComment())
injectHotkey('ß', () => this.toggleSidebar())
injectHotkey('Mod+[', () => this.outdent()) // Still accepted, because UsKeys is listed
injectHotkey('Mod+Ñ', () => this.search()) // Type error: Spanish isn't registered

injectHotkeys, injectHotkeyHint, injectFormatForDisplay, app hotkeys, custom hotkeys, and the Hotkey and HotkeyChord types all follow the registration.

What the registration changes

  • Replaces UsKeys unless kept. Include UsKeys in the union if you still want US punctuation like [. With keys: GermanKeys alone, Mod+[ fails type-checking because German types [ with AltGr or Option.
  • Always allowed. A to Z, 0 to 9, named keys (Escape, F1), and physical codes ([KeyS]) work under every registration.
  • Casing. Write letters uppercase (Mod+Ö, not Mod+ö), leaving ß and Turkish dotless ı as typed.
  • Shift-typed characters. Layout letters typed with Shift, such as Turkish İ or Swiss German È, require Shift+ (Shift+İ). Shift-typed symbols like § (via Shift+3 on German) match without Shift+.
  • Recorder. injectHotkeyRecorder captures whatever key the user presses, even outside your registered TypeScript union.

Available key sets

26 exported sets cover 33 layouts. Identical layouts share aliases, such as AustrianKeys and GermanKeys. Each set includes characters typed unshifted or with Shift across Windows, macOS, and Linux, excluding dead keys and AltGr or Option characters:

SetLayouts
UsKeysUS QWERTY (default)
UkKeysUK (British)
GermanKeys, AustrianKeysGerman and Austrian QWERTZ
SwissGermanKeys, SwissFrenchKeysSwiss German and Swiss French
FrenchKeys, BelgianKeysFrench and Belgian AZERTY
CanadianFrenchKeysCanadian French
SpanishKeys, LatinAmericanKeysSpanish (Spain) and Latin American
PortugueseKeys, BrazilianKeysPortuguese (Portugal) and Brazilian ABNT2
ItalianKeysItalian
DanishKeys, NorwegianKeysDanish and Norwegian
SwedishKeys, FinnishKeysSwedish and Finnish
IcelandicKeysIcelandic
CzechKeys, SlovakKeys, HungarianKeysCzech, Slovak, and Hungarian QWERTZ
CroatianKeys, SlovenianKeys, SerbianLatinKeysCroatian, Slovenian, and Serbian (Latin)
EstonianKeys, LithuanianKeysEstonian and Lithuanian
TurkishKeysTurkish Q
RomanianKeysRomanian (standard)
GreekKeys, RussianKeys, UkrainianKeys, BulgarianKeys, HebrewKeysGreek, Russian, Ukrainian, Bulgarian (BDS), and Hebrew

Polish and Latvian share US QWERTY base keys without AltGr, and most Dutch users use US International, so they don't need separate sets.

Example

The Keyboard Layouts example registers German keys and shows which hotkeys fire on a German keyboard.