Skip to content
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 Ctrl+Alt not being treated as a substitute for AltGr anymore #5552

Merged
merged 1 commit into from
Apr 28, 2020
Merged

Fix Ctrl+Alt not being treated as a substitute for AltGr anymore #5552

merged 1 commit into from
Apr 28, 2020

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Apr 24, 2020

Summary of the Pull Request

This PR fixes #5525 by re-adding range checks that where erroneously removed in a9c9714.

PR Checklist

Validation Steps Performed

  • Enabled a German keyboard layout
  • Entered <, +, 7, 8, 9, 0 while holding either Alt+Ctrl or AltGr and...
  • Ensuring that both produce |, ~, {, [, ], }

Copy link
Member Author

@lhecker lhecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple comments explaining my changes. 🙂

Here's the original code for reference.

// -> Get the char from the virtual key.
ch = LOWORD(MapVirtualKeyW(keyEvent.GetVirtualKeyCode(), MAPVK_VK_TO_CHAR));
ch = keyEvent.GetVirtualKeyCode();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've taken the liberty to remove this call to MapVirtualKeyW.
As far as I now understood virtual key codes in Windows, the numeric values of the vkeys for Space and A-Z are identical with their respective ASCII value. As such a call to MapVirtualKeyW is IMO unnecessary.
Am I seing this correctly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you are correct.

@@ -530,7 +530,7 @@ bool TerminalInput::HandleKey(const IInputEvent* const pInEvent)

// This section is similar to the Alt modifier section above,
// but handles cases without Ctrl modifiers.
if (keyEvent.IsAltPressed() && keyEvent.GetCharData() != 0)
if (keyEvent.IsAltPressed() && !keyEvent.IsCtrlPressed() && keyEvent.GetCharData() != 0)
Copy link
Member Author

@lhecker lhecker Apr 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had to add these two additional checks, because Alt+Ctrl combinations actually sometimes do carry character data!
For instance Ctrl+Alt+< will send an KeyEvent with the CharData being |. 😲
The old condition here (keyEvent.IsAltPressed() && keyEvent.GetCharData() != 0) would thus incorrectly match and Ctrl+Alt+< would send ^[| instead of |.

(This wasn't an issue in the past when HandleKey was only called with CharData in a much more limited set of circumstances. Nowadays it's almost always invoked with CharData.)

@lhecker
Copy link
Member Author

lhecker commented Apr 24, 2020

BTW did something change recently?
My Dev build feels crazy snappy nowadays, even if I got a debugger attached. 🤯
That definitely wasn't the case a month ago or so. Is this because of the new til::bitmap rendering?

@DHowett-MSFT
Copy link
Contributor

I hope that's it 😁

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I'm thinking that with the research you've got here, this might actually be more robust than it used to be. Thanks for linking directly to what this originally looked like, made reviewing this much easier.

@zadjii-msft zadjii-msft added Area-Input Related to input processing (key presses, mouse, etc.) Area-VT Virtual Terminal sequence support labels Apr 28, 2020
Copy link
Contributor

@DHowett-MSFT DHowett-MSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me. Thank you 😄

// For instance using a German keyboard both AltGr+< and Alt+Ctrl+< produce a | (pipe) character.
// The below condition primitively ensures that we allow all common Alt+Ctrl combinations
// while preserving most of the functionality of Alt+Ctrl as a substitute for AltGr.
if (ch == UNICODE_SPACE || (ch > 0x40 && ch <= 0x5A))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see: this change is safe because 0x20 & 0b11111 is 0 (we didn't need to set it to 0x40 just to strip off the top few bits). Clever.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DHowett-MSFT Did you ever see this article? https://garbagecollected.org/2017/01/31/four-column-ascii/
You probably know everything about this already, but for me it was pretty eye opening regardless...
It quickly shows you why ^␣ is actually the same as ^@ and why ^[ is the same as the ESC character. It's a much better representation of ASCII as the square one you can find everywhere else (including Wikipedia). 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually used to have a giant version of this table printed in my office, which has been immensely helpful

@DHowett-MSFT DHowett-MSFT merged commit 9247ff0 into microsoft:master Apr 28, 2020
@lhecker lhecker deleted the fix-5525-altgr-alt-ctrl branch April 29, 2020 20:02
@ghost
Copy link

ghost commented May 5, 2020

🎉Windows Terminal Release Candidate v0.11.1251.0 (1.0rc1) has been released which incorporates this pull request.:tada:

Handy links:

@mintty
Copy link

mintty commented May 13, 2020

I think this is a misguided change and should be reverted, see my comment at
#5525 (comment)

@DHowett
Copy link
Member

DHowett commented Jul 2, 2020

🎉 Once again, thanks for the contribution!

This pull request was included in a set of conhost changes that was just
released with Windows Insider Build 20161.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Area-VT Virtual Terminal sequence support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ctrl+Alt+'char' generates other chars then 'AltGr' (Germany Layout) v0.11.1121.0
5 participants