AltGr characters fire unmodified hotkeys on the same physical key #169
Describe the bug#
On layouts with AltGr (German, Polish, …), typing an AltGr character fires an unmodified single-key hotkey on the same physical key.
- German AltGr+M types
µand fires aMhotkey. - Polish AltGr+C types
ćand fires aChotkey. - German AltGr+Q types
@and fires aQhotkey.
In _match.ts, modifiersMatch clears Ctrl and Alt when altGraph is set (lines 86–87). The code fallback (lines 60–64) then maps KeyM → M, which matches. For ć, the Latin-letter guard at line 53 is skipped because normalized.alt is true under AltGr. µ and @ aren't Latin letters, so the guard doesn't apply at all.
Reproduce#
import { matchesKeyboardEvent } from '@tanstack/hotkeys'
// What Chrome on Windows reports for AltGr+<key>: Ctrl+Alt plus the AltGraph modifier state.
const altGr = (key: string, code: string) =>
({ type: 'keydown', key, code, ctrlKey: true, altKey: true, shiftKey: false, metaKey: false,
isComposing: false, getModifierState: (k: string) => k === 'AltGraph' }) as unknown as KeyboardEvent
matchesKeyboardEvent(altGr('µ', 'KeyM'), 'M', 'windows') // true, expected false
matchesKeyboardEvent(altGr('ć', 'KeyC'), 'C', 'windows') // true, expected false
matchesKeyboardEvent(altGr('@', 'KeyQ'), 'Q', 'windows') // true, expected false
Expected#
A key press that produced a character through AltGr is text input and should not fall back to the physical key. Only a direct key match should count, as line 30 already does for hotkeys with Ctrl/Alt.
Versions#
@tanstack/hotkeys 0.11.0 and @tanstack/react-hotkeys 0.13.0. _match.ts on main still has the same code.
KevinVandy closed this
Sign in to join this conversation.