Repository navigation
Closed
Labels
Area-TerminalControlIssues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.)Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.)Help WantedWe encourage anyone to jump in on these.We encourage anyone to jump in on these.In-PRThis issue has a related PRThis issue has a related PRIssue-BugIt either shouldn't be doing this or needs an investigation.It either shouldn't be doing this or needs an investigation.Needs-Tag-FixDoesn't match tag requirementsDoesn't match tag requirementsPriority-3A description (P3)A description (P3)Product-TerminalThe new Windows Terminal.The new Windows Terminal.
Milestone
Description
Windows Terminal version
1.21.1272.0
Windows build number
10.0.22631.0
Other Software
wsl terminal, powershell, etc.
Steps to reproduce
Sequential numpad keys combinations with the ALT key pressed to insert special characters ( for example the most common ones such as { with ALT+123, ~ with ALT+126, or the tilde ~ with ALT+126, etc. ) do not work anymore.
The latest working version is Microsoft.WindowsTerminal.Preview 1.20.11215.0, the next current one (1.21.1272.0) broke this functionality.
Expected Behavior
On previous versions the combination works
raksati@wsl:$ showkey -a
Press any keys - Ctrl-D will terminate this program
` 96 0140 0x60
^D 4 0004 0x04
raksati@wsl:~$
Actual Behavior
nothing is detected:
raksati@wsl:$ showkey -a
Press any keys - Ctrl-D will terminate this program
^D 4 0004 0x04
raksati@wsl:~$
Metadata
Metadata
Assignees
Labels
Area-TerminalControlIssues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.)Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.)Help WantedWe encourage anyone to jump in on these.We encourage anyone to jump in on these.In-PRThis issue has a related PRThis issue has a related PRIssue-BugIt either shouldn't be doing this or needs an investigation.It either shouldn't be doing this or needs an investigation.Needs-Tag-FixDoesn't match tag requirementsDoesn't match tag requirementsPriority-3A description (P3)A description (P3)Product-TerminalThe new Windows Terminal.The new Windows Terminal.
Activity
j4james commentedon May 28, 2024
Thanks for the report!
I suspect this might be related to PR #17067. There are a couple of places in the code that mention Alt-Numpad being handled in
TSFInputControl. For example see here:terminal/src/cascadia/TerminalApp/TerminalPage.cpp
Lines 1439 to 1442 in 5d1cf1a
But
TSFInputControlhas now been replaced, so perhaps that functionality was lost in the rewrite./cc Leonard Hecker (@lhecker)
lhecker commentedon May 28, 2024
It works in conhost because that one doesn't rely on the WinRT TSF stack via TextInputHost, and so it'll receive the Alt+Numpad key regularly via
WM_CHAR. The weirdest thing is that even if I remove the new TSF implementation entirely (doesn't get instantiated) it'll not fix the issue. Does that mean the only way to get Alt+Numpad keys in a WinUI app is by usingCoreTextServicesManager? That'd be quite surprising and kind of sad, because we fundamentally can't use that class.lhecker commentedon May 28, 2024
Wow. Just after I wrote that I found that switching my keyboard layout to Korean or any other "complex" language fixes the issue. What in the heck!
lhecker commentedon May 29, 2024
So, with all that said, I think it'd be way easier to just write our own Alt+Numpad support in
TermControlfrom scratch. ConEmu got all the info we need: https://conemu.github.io/en/AltNumpad.htmlIf anyone wants to give it a shot, please do so!
Windows internals for the curious follow below:
I spent an unfathomable amount of time debugging this. 😄
This happens basically because the UWP implementation of TSF does not like its own non-UWP sibling very much and switches off when it sees it.
I tried solving this issue by adding this to
TermControl:(And
NotifyFocusEnter()/NotifyFocusLeave()calls must be added of course.)The problem is that for some mysterious reason these callbacks won't get called if our new TSF implementation got focus simultaneously (which it needs because otherwise we have no IME).
We call
ITfDocumentMgr::CreateContexthere:terminal/src/tsf/Implementation.cpp
Line 42 in 13de7c6
It's implemented by
CDocumentInputManager::CreateContextwhich callsQueryInterfaceon ourITfContextOwnerCompositionSinkto check if it implementsITextInputClientOwner(86b4403f-c187-4a8b-b13e-c93c4ad1078c) and passes that as aboolto theCInputContextinstance that's returned as the "context".(The TSF context is mostly an adapter between the public msctf.h interfaces and the private implementation. We need our own context because we need
TS_SS_TRANSITORY. SeeImplementation.cppfor lots of details about this.)CInputContext::GetStatusthen adapts ourImplementation::GetStatussomewhat like this:The existence of this
TS_SS_UWPCONTROLis what makes and breaks not just the Alt+Numpad support, but seemingly any support for any input whatsoever. If that flag is missing (= no TSF3), then somewhere something betweenTextInputHostandCoreTextEditContextbreaks down. I couldn't quite figure out where and what exactly.I think that's a bug in the TSF implementation. The lack of Alt+Numpad support is likely a fallout from this, because when that flag is missing and
TextInputHostis not sending any input anymore, then it should also re-enable sending Alt+Numpad viaWM_CHAR, just like how it works for regular Win32 applications.In any case, if I pass any
IUnknowninstance as theITextInputClientOwnerin ourImplementation, then that will fix the issue with the context that WinUI holds, becauseTextInputHostwill then send messages again.The only problem with all that is that it doesn't solve the focus problem: To make this work we need to give both WinUI's context (for Alt+Numpad) and our context (= our IME) focus at the same, which means that both will receive the same input at the same time. That's really really bad, because TSF3 doesn't use
TS_SS_TRANSITORYand I don't want to deal with the terminal-specific issues that this results in.inoperable commentedon Jul 4, 2024
inoperable commentedon Jul 4, 2024
lhecker commentedon Jul 8, 2024
inoperable commentedon Jul 8, 2024
Implement Alt-Numpad handling (microsoft#17637)
Implement Alt-Numpad handling (#17637)