Skip to content

win32: pass key text for Ctrl-only key presses - #6

Open
jumptable wants to merge 1 commit into
Codavo:mainfrom
jumptable:win32-ctrl-key-text
Open

jumptable wants to merge 1 commit into
Codavo:mainfrom
jumptable:win32-ctrl-key-text

Conversation

@jumptable

Copy link
Copy Markdown

On win32, Ctrl+[, Ctrl+i, Ctrl+m (and punctuation like Ctrl+,) send nothing to the terminal.

Cause: Ctrl+key presses reach the core as a raw WM_KEYDOWN event with no utf8. The WM_CHAR that follows is a C0 control character, which handleTextInput intentionally drops. The legacy encoder handles most Ctrl keys from the logical key, but leaves [, i, m (CSI u per fixterms) and punctuation to the event's text, so they produce no output.

Fix: for Ctrl-only presses, pass the key's unshifted character as utf8, matching what the GTK apprt sends. Shift/Alt/AltGr/Super combinations are unchanged.

Tested on Windows 11 (x64 build cross-compiled with Zig 0.16 from WSL), legacy encoding, raw byte logger:

Key Before After
Ctrl+[ (nothing) \e[91;5u
Ctrl+i (nothing) \e[105;5u
Ctrl+m (nothing) \e[109;5u
Ctrl+, (nothing) \e[44;5u
Ctrl+a \x01 \x01
Esc \e \e

AI disclosure: I used Claude Code (Claude Opus 5.5) to trace the cause through App.zig and key_encode.zig, write the change, and draft this description. I reviewed the change and ran the tests above myself.

🤖 Generated with Claude Code

On win32, a Ctrl+key press reaches the core as a raw WM_KEYDOWN event
with no utf8 text, and the WM_CHAR generated for it is a C0 control
character that handleTextInput intentionally drops. The legacy encoder
handles most Ctrl keys from the logical key alone, but leaves Ctrl+[,
Ctrl+i and Ctrl+m (CSI u per fixterms) and punctuation such as Ctrl+,
to the event's text, so those keys sent nothing at all.

Pass the key's unshifted character as text for Ctrl-only presses, as
the GTK apprt does, so the encoder produces the same output as on other
platforms: Ctrl+[ -> \e[91;5u, Ctrl+i -> \e[105;5u, Ctrl+m -> \e[109;5u,
Ctrl+, -> \e[44;5u. Ctrl+letters and digits are unchanged. Presses with
Shift, Alt (including AltGr) or Super keep the existing behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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