Fix SDL_TEXTINPUT ignoring Shift/Caps Lock for letter keys#742
Open
MrGPUs wants to merge 1 commit into
Open
Conversation
The TEXTINPUT event generated in generateKeyEvent() uses the raw SDL keycode (`keysym.sym & 0xff`) as the text character. For letter keys a-z, this always produces the lowercase character regardless of whether Shift or Caps Lock is active. Real SDL2 generates TEXTINPUT through the OS input method, which applies modifier state to produce the correct case. Games that derive character input from SDL_TEXTINPUT (e.g. ScummVM's obtainUnicode() which peeks the event queue for TEXTINPUT before falling back to the Shift-based mapKey() path) receive the wrong character for Shift+letter / Caps+letter combinations. The fix checks keysym.mod (already correctly populated by xkeyboardToSDLMod since commit 5deef26) for KMOD_SHIFT or KMOD_CAPS, and applies the standard uppercase transformation (c &= ~0x20) to letters a-z before writing the TEXTINPUT text. This is complementary to issue clementgallet#405 (Shift+Click) — that fix addressed the mod field on SDL_KEYDOWN events; this addresses the text content of SDL_TEXTINPUT events, which is a separate code path. Only ASCII letters are handled; non-letter shifted characters (Shift+1 → '!') would require a full keyboard layout lookup and are left for a future change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
generateKeyEvent()ininputevents.cppgeneratesSDL_TEXTINPUTevents using the raw SDL keycode (keysym.sym & 0xff), which always produces lowercase for letter keys regardless of modifier state. Real SDL2 generates TEXTINPUT through the OS input method, which applies Shift/Caps Lock.This breaks games that derive character input from
SDL_TEXTINPUTrather than fromSDL_KEYDOWN+ modifier flags — for example, ScummVM'sobtainUnicode()peeks the event queue for TEXTINPUT and uses it directly, bypassing its own Shift→uppercase fallback path.Fix
When
keysym.modhasKMOD_SHIFTorKMOD_CAPSset, applyc &= ~0x20to letters a–z before writing the TEXTINPUT text. This matches real SDL2 behavior for ASCII letters.Only letters are handled; non-letter shifted characters (e.g. Shift+1 →
!) would require a keyboard layout lookup and are left for a future change.Relation to #405
Issue #405 (Shift+Click) was fixed by commits
5deef26(mod field on SDL_KEYDOWN) and422018a(X11/XCB modifier state). Those fixes address modifier flags on key events — this PR addresses the text content ofSDL_TEXTINPUTevents, which is a separate code path that the earlier fixes don't reach.