Skip to content

Fix Hankaku/Zenkaku key handling on Windows Japanese keyboard layouts - #2109

Open
hinatamaxxx wants to merge 1 commit into
moonlight-stream:masterfrom
hinatamaxxx:fix-windows-jis-hankaku-zenkaku
Open

hinatamaxxx wants to merge 1 commit into
moonlight-stream:masterfrom
hinatamaxxx:fix-windows-jis-hankaku-zenkaku

Conversation

@hinatamaxxx

Copy link
Copy Markdown

Problem

On Windows with a Japanese keyboard layout, holding down the Hankaku/Zenkaku key (SDL_SCANCODE_GRAVE, scan code 0x29) causes the host's IME to toggle rapidly and continuously.

Root Cause

On Windows Japanese keyboard layouts (LANG_JAPANESE), the Hankaku/Zenkaku key reports its physical press as WM_KEYUP (SDL_RELEASED) and its physical release as WM_KEYDOWN (SDL_PRESSED).

  1. Forwarding those transitions directly leaves the host seeing the key as held down or mismatched.
  2. When the key is held down on the client, Windows keyboard auto-repeat delivers additional WM_KEYUP (SDL_RELEASED) events without event->repeat set, bypassing Moonlight's if (event->repeat) return; filter.

Fix

  • On Windows when the active keyboard layout's primary language is LANG_JAPANESE, handle SDL_SCANCODE_GRAVE as a single complete tap (KEY_ACTION_DOWN followed immediately by KEY_ACTION_UP) on the first SDL_RELEASED.
  • Track held state via m_HankakuZenkakuHeld so subsequent auto-repeated SDL_RELEASED events are ignored until SDL_PRESSED (physical release) or raiseAllKeys() (focus loss / ungrab).
  • Non-Windows platforms and non-Japanese keyboard layouts are completely unaffected.

Testing

Tested on Windows 11 client (Japanese JIS keyboard, Microsoft IME) streaming to a Windows 11 host (Sunshine):

  • Pressing Hankaku/Zenkaku once toggles the host IME exactly once.
  • Holding Hankaku/Zenkaku down for ~3 seconds toggles the host IME exactly once (no rapid toggling).
  • Focus loss (Alt+Tab) properly resets held state via raiseAllKeys().

@cgutman

cgutman commented Nov 27, 2026

Copy link
Copy Markdown
Member

Is SDL3 handling this situation properly? If we're having to invoke native OS APIs to determine what to do with a keypress, it seems like it's not.

It also looks like the Hankaku/Zenkaku key is supposed to be SDL_SCANCODE_LANG5 not SDL_SCANCODE_GRAVE. Any idea why we're receiving it as the latter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants