Repository navigation
Description
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.
Mike Griese (@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 thatTerminalInputdefinitely invokes_pfnWriteEventswith a\x1b\x00sequence.
But then showkey shows a^[^Rsequence 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.
- On a en-us keyboard, '@' is shift+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]
- When we get back to
TerminalInput::HandleKey, we end up skipping that branch, because thechwas0n50, which is0x32, 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 Mike Griese (@zadjii-msft) in #4192 (comment)
Activity
zadjii-msft commentedon Apr 1, 2020
master, Conhost+conpty, Ctrl+alt+space, (i/o modes):(0x 1f7, 0x f)(Win32 input)The interesting input here is
Down: 1 Repeat: 1 KeyCode: 0x32 ScanCode: 0x3 Char: \0 (0x0) KeyState: 0x1amaster, Conhost+conpty, Ctrl+alt+space, (i/o modes):(0x 3f7, 0x f)(VT input)master, Conhost, Ctrl+alt+space, (i/o modes):(0x 1f7, 0x f)(Win32 input)master, Conhost, Ctrl+alt+space, (i/o modes):(0x 3f7, 0x f)(VT input)master, Conhost, Ctrl+alt+shift+2, (i/o modes):(0x 1f7, 0x f)(Win32 input)NOTE: this keystroke is what conpty is attempting to replicate
zadjii-msft commentedon Apr 1, 2020
Okay I see what the problem is - I think it is the think Leonard Hecker (@lhecker) called out in #4192. Even in straight-up conhost, Ctrl+alt+shift+2 does not generate
\x1b\x0.IMO, Leonard Hecker (@lhecker) if you want to do the fix proposed in #4192, the
ch != 0fix, then I say go for it, and add this to the growing list of bugs that PR fixes 😆I'll submit the other thing I found during the course of this investigation, but that will effectively hide the
showkey -arepro case in the Terminal.[-]Investigate Ctrl+Alt+Space in conpty[/-][+]Ctrl+Alt+Shift+2 doesn't send NUL in VT input mode[/+]lhecker commentedon Apr 1, 2020
Mike Griese (@zadjii-msft) I believe we're misunderstanding each other.
If I press Ctrl+Alt+Space or Ctrl+Alt+Shift+2,
showkey -awill show the following output:Ctrl+Altconditionshowkey -aoutputch >= 0x40 && ch < 0x7F^@ch != 0^[^RBut as far as I can see it should be
^[^@, right?Or am I misunderstanding you and
^[^Ris actually correct? (...because, as you mentioned above, there's another bug involved here, which distorts the showkey output?)That said, would you'd like me to modify #4192 to use a
ch != 0condition?I can't decide by myself if I should. 😄
zadjii-msft commentedon Apr 1, 2020
Oh jeez, you should be seeing
^[^@. Now I'm not sure what the right fix is.lhecker commentedon Apr 1, 2020
I figured it out. I didn't realize I had to manually attach myself to OpenConsole.exe for debugging. 🙈
You basically already said all the right things (especially steps 2 and 3 above), but I didn't understand you, because I've been lacking the knowledge how all the code works together.
Anyways... I fixed the problem. (lol)
Turns out if you use
MapVirtualKeyWyou're probably doing something wrong. I guess? 😄I replaced this:
terminal/src/terminal/input/terminalInput.cpp
Line 488 in 713550d
with a call to
ToUnicodeEx, similar toTerminal::_CharacterFromKeyEvent.This call allows us to reliably turn the input event Alt+Ctrl+Shift+2 into an Alt+Ctrl+@ event, which then gets translated to
Alt+0x00and sent away. 🙂Would you like me to add it to #4192 or open a separate PR afterwards?
I believe it makes sense to fix it separately.
zadjii-msft commentedon Apr 1, 2020
Literally my least favorite thing about using VS. JUST ATTACH TO CHILD PROCESSES. Or at least give me an option to auto-attach, sheesh.
You're sure right about that 😄 Glad you got that figured out!
Let's open another PR, since this has gotten bigger than a oneline fix☺️
5 remaining items
This fixes C-M-space for WSL but not for Win32, but I'm not sure ther…
DHowett-MSFT commentedon Apr 3, 2020
Milestoning this for 1.x and taking off Triage
Fixed #5205: Ctrl+Alt+2 doesn't send ^[^@ (#5272)
Merged PR 5676764: Migrate OSS up to 16d00a6