Ctrl+Alt+Shift+2 doesn't send NUL in VT input mode #7244

Open
opened 2026-01-31 00:58:54 +00:00 by claunia · 0 comments
Owner

Originally created by @zadjii-msft on GitHub (Apr 1, 2020).

Originally assigned to: @lhecker on GitHub.

@zadjii-msft:

Okay so Ctrl+Alt+Space was fixed for conhost, but it looks like it's still broken in the Terminal 😢 Now it's just generating a ^@, a single NUL.

I think the Terminal is synthesizing the right sequence, but maybe conpty is generating the wrong input for it now, or maybe the input that's generated by conpty doesn't get re-translated back to ^[^@ correctly. I can try to keep investigating to figure out where the miscommunication is, if you need help.

@lhecker:

@zadjii-msft Yeah I was just about to say that as well.

As I wrote above the most puzzling thing for me though is if you change this if condition (line 510) to a simple ch != 0 - which should be correct as well.
If you attach a debugger you'll see that TerminalInput definitely invokes _pfnWriteEvents with a \x1b\x00 sequence.
But then showkey shows a ^[^R sequence instead. How can this happen? > I don't understand how such a benign change to the if condition can cause this. 😞

Okay I maybe saw what happened here.

  1. On a en-us keyboard, '@' is shift+2.
  2. When conpty sees a \x1b\x0, it converts it to [Shift_down, Ctrl_down, Alt_down, 2_down, 2_up, Alt_up, Ctrl_up, Shift_up].
    • I did not pay a ton of attention to the keys that got synthesized here. I need to re-investigate the [2_down, 2_up]
  3. When we get back to TerminalInput::HandleKey, we end up skipping that branch, because the ch was 0n50, which is 0x32, which is '2'.

I'm not sure what's exactly the right behavior here. I'd think we probably should send a different key, but I'll need to investigate more. It's possible that the ch != 0 change would work just fine, but I want to make sure that the upstream input from conpty is actually correct.
I've got a braindead fix that would fix showkey -a, but that doesn't really resolve the issue here for Win32 applications unfortunately, so I'm gonna file a separate issue to track this investigation.

Originally posted by @zadjii-msft in https://github.com/microsoft/terminal/pull/4192#issuecomment-607326733

Originally created by @zadjii-msft on GitHub (Apr 1, 2020). Originally assigned to: @lhecker on GitHub. @zadjii-msft: > Okay so <kbd>Ctrl+Alt+Space</kbd> was fixed for conhost, but it looks like it's still broken in the Terminal 😢 Now it's just generating a `^@`, a single NUL. > > I think the Terminal is synthesizing the right sequence, but maybe conpty is generating the wrong input for it now, or maybe the input that's generated by conpty doesn't get re-translated back to `^[^@` correctly. I can try to keep investigating to figure out where the miscommunication is, if you need help. @lhecker: > @zadjii-msft Yeah I was just about to say that as well. > > As I wrote above the most puzzling thing for me though is if you change [this if condition (line 510)](https://github.com/microsoft/terminal/pull/4192/files#diff-3895074b0184ca0d36ef271db540a282R510) to a simple `ch != 0` - which _should_ be correct as well. > If you attach a debugger you'll see that `TerminalInput` _definitely_ invokes `_pfnWriteEvents` with a `\x1b\x00` sequence. > But then showkey shows a `^[^R` sequence instead. How can this happen? > I don't understand how such a benign change to the if condition can cause this. :disappointed: Okay I maybe saw what happened here. 1. On a en-us keyboard, '@' is <kbd>shift+2</kbd>. 2. When conpty sees a `\x1b\x0`, it converts it to [Shift_down, Ctrl_down, Alt_down, 2_down, 2_up, Alt_up, Ctrl_up, Shift_up]. - I did not pay a ton of attention to the keys that got synthesized here. I need to re-investigate the [2_down, 2_up] 3. When we get back to `TerminalInput::HandleKey`, we end up skipping that branch, because the `ch` was `0n50`, which is `0x32`, which is `'2'`. I'm not sure what's exactly the right behavior here. I'd think we probably should send a different key, but I'll need to investigate more. It's possible that the `ch != 0` change would work just fine, but I want to make sure that the upstream input from conpty is _actually_ correct. I've got a [braindead fix](https://github.com/microsoft/terminal/commit/77eee7066e5606f32359ec5ea8b291e42aa86ca9) that would fix `showkey -a`, but that doesn't really resolve the issue here for Win32 applications unfortunately, so I'm gonna file a separate issue to track this investigation. _Originally posted by @zadjii-msft in https://github.com/microsoft/terminal/pull/4192#issuecomment-607326733_
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#7244