Skip to content

Fix SDL_TEXTINPUT ignoring Shift/Caps Lock for letter keys#742

Open
MrGPUs wants to merge 1 commit into
clementgallet:masterfrom
MrGPUs:fix/textinput-shift-modifier
Open

Fix SDL_TEXTINPUT ignoring Shift/Caps Lock for letter keys#742
MrGPUs wants to merge 1 commit into
clementgallet:masterfrom
MrGPUs:fix/textinput-shift-modifier

Conversation

@MrGPUs

@MrGPUs MrGPUs commented Jun 12, 2026

Copy link
Copy Markdown

Summary

generateKeyEvent() in inputevents.cpp generates SDL_TEXTINPUT events 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_TEXTINPUT rather than from SDL_KEYDOWN + modifier flags — for example, ScummVM's obtainUnicode() peeks the event queue for TEXTINPUT and uses it directly, bypassing its own Shift→uppercase fallback path.

Fix

When keysym.mod has KMOD_SHIFT or KMOD_CAPS set, apply c &= ~0x20 to 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) and 422018a (X11/XCB modifier state). Those fixes address modifier flags on key events — this PR addresses the text content of SDL_TEXTINPUT events, which is a separate code path that the earlier fixes don't reach.

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.
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.

1 participant