-
Notifications
You must be signed in to change notification settings - Fork 8.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix VT sequences for Ctrl+Alt+? input #4947
Conversation
## Summary of the Pull Request Ctrl+/ and Ctrl-? are complicated in VT input. * C-/ is supposed to be `^_` (the C0 charater US) * C-? is supposed to be `DEL` * C-M-/ is supposed to be `^[^/` * C-M-? is supposed to be `^[?` The astute reader will note that these characters also share the same key on a standard en-us keyboard layout, which makes the problem even more complicated. This PR does a better job of handling these weird cases. ## PR Checklist * [x] Closes #3079 * [x] I work here * [x] Tests added/passed * [n/a] Requires documentation to be updated ## Validation Steps Performed * ran tests * checked `showkey -a` in gnome-terminal * checked `showkey -a` in conhost * checked `showkey -a` in Windows Terminal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you check this with an alternate keyboard layout? I hope so. It looks like it will be robust enough to handle it with the VkKeyScan
matching.
The only other comment I had was the one Carlos flagged with the typo. So approving.
Co-Authored-By: Carlos Zamora <carlos.zamora@microsoft.com>
src/terminal/input/terminalInput.cpp
Outdated
const bool shift = keyEvent.IsShiftPressed(); | ||
|
||
// From the KeyEvent we're translating, synthesize the equivalent VkKeyScan result | ||
const short keyScanFromEvent = keyEvent.GetVirtualKeyCode() | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is quite clever!
should it be a local static function that takes a keyEvent instead? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(i don't think it should be a member on keyevent because that's too win32-specific)
src/terminal/input/terminalInput.cpp
Outdated
const bool shift = keyEvent.IsShiftPressed(); | ||
|
||
// From the KeyEvent we're translating, synthesize the equivalent VkKeyScan result | ||
const short keyScanFromEvent = keyEvent.GetVirtualKeyCode() | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(i don't think it should be a member on keyevent because that's too win32-specific)
For the record, I think this is wrong. If you look at Mintty, or Xterm (with the meta sends escape mode set), you'll get different results: Ctl+/ is Notice how it all fits a pattern. Gnome-terminal doesn't distinguish between Ctl+Alt and Alt, which definitely seems like a bug to me. |
@j4james great catch! I was using gnome-terminal to test, not xterm. That certainly does make more sense. I'll make sure that roundtrips as nicely through conpty as the other ones did |
Gah okay. I concur that the fixed behavior is more correct, but now ctrl+alt+? falls into the #879 category of keys. We can't differentiate between that and Alt+Bksp, but that's probably okay. |
…om/Microsoft/Terminal into dev/migrie/b/3079-C-M-questionmark
In the future, I'd like to see if we can't just not special-case these keys. |
Hello @DHowett-MSFT! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
## Summary of the Pull Request Ctrl+/ and Ctrl-? are complicated in VT input. * C-/ is supposed to be `^_` (the C0 character US) * C-? is supposed to be `DEL` * C-M-/ is supposed to be `^[^_` (ESC US) * C-M-? is supposed to be `^[^?` (ESC DEL) The astute reader will note that these characters also share the same key on a standard en-us keyboard layout, which makes the problem even more complicated. This PR does a better job of handling these weird cases. # References * #3079 - At first, I thought this PR would close this issue, but as I've learned below, this won't solve that one. This bug was merely found during that investigation. ## PR Checklist * [x] Related to #3079 * [x] I work here * [x] Tests added/passed * [n/a] Requires documentation to be updated ## Validation Steps Performed * ran tests * checked `showkey -a` in gnome-terminal, which gives you the wrong results for C-M-/, C-M-? * checked `showkey -a` in xterm, which gives you the _right_ results for C-M-/, C-M-? * checked `showkey -a` in conhost * checked `showkey -a` in Windows Terminal (cherry picked from commit d50409b)
uiKeystate = LEFT_CTRL_PRESSED | LEFT_ALT_PRESSED; | ||
vkey = LOBYTE(VkKeyScan(L'/')); | ||
s_pwszInputExpected = L"\x1b\x1f"; | ||
TestKey(pInput, LEFT_CTRL_PRESSED | LEFT_ALT_PRESSED, vkey, L'/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW This particular call fails the test if you've got a non-US keyboard attached. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that bit is unfortunate. We've got a couple other tests that make assumptions about the environment they're running in (mostly around language and system codepage)
🎉 Handy links: |
Summary of the Pull Request
Ctrl+/ and Ctrl-? are complicated in VT input.
^_
(the C0 character US)DEL
^[^_
(ESC US)^[^?
(ESC DEL)The astute reader will note that these characters also share the same key on a
standard en-us keyboard layout, which makes the problem even more complicated.
This PR does a better job of handling these weird cases.
References
PR Checklist
Validation Steps Performed
showkey -a
in gnome-terminal, which gives you the wrong results for C-M-/, C-M-?showkey -a
in xterm, which gives you the right results for C-M-/, C-M-?showkey -a
in conhostshowkey -a
in Windows Terminal