Feature: support physical key (event.code) matching for non-Latin IME input methods
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 719
- Forks
- 47
- Avg merge
- 5d 5h
- Merged PRs (30d)
- 1
Description
TanStack Hotkeys version
0.7.0
Framework/Library version
React 19
Describe the bug and the steps to reproduce it
When a non-Latin input method is active (e.g., Korean, Japanese, Chinese, Russian IME), single-key hotkeys do not fire because event.key produces a non-Latin character instead of the expected ASCII letter.
For example, with Korean input active, pressing the physical A key produces:
event.key='ㅁ'event.code='KeyA'
So a hotkey registered as A will not match.
The current matching logic in matchesKeyboardEvent (match.ts) trusts the keyboard layout for non-ASCII letters without Alt:
if (
isSingleLetterKey(eventKey) &&
(/^[A-Za-z]$/.test(eventKey) || !event.altKey)
) {
return false // trusts layout, never reaches event.code fallback
}
This correctly supports alternative Latin layouts (Dvorak, Colemak, AZERTY). However, for IME-based input methods where the physical layout is QWERTY but the output characters are non-Latin, the event.code fallback is never reached, and the hotkey silently fails.
Steps to reproduce:
- Switch OS input method to Korean (or any non-Latin IME)
- Register
useHotkey('A', callback) - Press the physical
Akey - Callback never fires
This affects all non-Latin IME users globally: Korean, Japanese, Chinese, Russian, Arabic, Thai, and more. Users frequently switch between their native input method and English throughout their workflow and expect single-key shortcuts to work without manually switching input language first.
Proposed solution
An explicit opt-in option for event.code based (physical key) matching:
// Per-registration
useHotkey('A', callback, { matchBy: 'code' })
// Or via useHotkeys
useHotkeys(
[
{ hotkey: 'A', callback: handleA },
{ hotkey: 'S', callback: handleS },
],
{ matchBy: 'code' }
)
When matchBy: 'code' is set, matchesKeyboardEvent would compare the hotkey against event.code (e.g., 'A' matches KeyA) instead of event.key. The default remains 'key' to preserve current behavior.
This avoids the conflict with automatic fallback approaches (see #53) because the consumer explicitly opts in per registration. Applications that need layout-aware matching (Dvorak, Colemak) keep the default 'key' behavior, while applications that need physical key matching can opt in.
Related
- #65 (Discussion: Add support for international keyboard layouts)
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
No response
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
- I intend to try to help solve this bug with my own PR
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with matchesKeyboardEvent in match.ts, then trace the useHotkey and useHotkeys registration APIs described in the issue. The change is done when callers can opt into event.code matching while the default event.key behavior remains unchanged, including support for the existing layout-aware behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100