You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add `matchBy` option for physical key (`event.code`) matching
6
+
7
+
Added a new `matchBy` option to `HotkeyOptions` that allows matching hotkeys by physical key position (`event.code`) instead of the default layout-aware matching (`event.key`). This enables hotkeys to work correctly when a non-Latin IME is active and `event.key` produces non-Latin characters.
Controls whether hotkeys match by `event.key` (layout-aware) or `event.code` (physical key position). Defaults to `'key'`.
212
+
213
+
Use `'code'` when a non-Latin IME is active and `event.key` produces non-Latin characters instead of the expected ASCII letter. For example, pressing the physical `A` key with a non-Latin IME produces a non-Latin character in `event.key`, but `event.code` still reports `'KeyA'`.
> `matchBy: 'code'` ignores the active keyboard layout. If your users rely on alternative Latin layouts (Dvorak, Colemak, AZERTY), keep the default `'key'` so shortcuts follow their remapped layout.
234
+
208
235
## Stale Closure Prevention
209
236
210
237
The `useHotkey` hook automatically syncs the callback on every render, so you never need to worry about stale closures:
/** Whether to match by `event.key` (layout-aware, default) or `event.code` (physical key position). Use `'code'` when a non-Latin IME is active. Defaults to 'key' */
54
+
matchBy?: 'key'|'code'
53
55
}
54
56
55
57
/**
@@ -514,6 +516,7 @@ export class HotkeyManager {
514
516
event,
515
517
registration.parsedHotkey,
516
518
registration.options.platform,
519
+
registration.options.matchBy,
517
520
)
518
521
519
522
if(matches){
@@ -545,6 +548,7 @@ export class HotkeyManager {
545
548
event,
546
549
registration.parsedHotkey,
547
550
registration.options.platform,
551
+
registration.options.matchBy,
548
552
)
549
553
){
550
554
this.#executeHotkeyCallback(registration,event)
@@ -637,19 +641,6 @@ export class HotkeyManager {
637
641
constparsed=registration.parsedHotkey
638
642
constreleasedKey=normalizeKeyName(event.key)
639
643
640
-
// Reset if the main key is released
641
-
// Compare case-insensitively for single-letter keys
0 commit comments