From bfa16c64f26b83b2dd51bc9bdb135d4896d61197 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Sat, 25 Apr 2020 00:22:05 +0200 Subject: [PATCH] Fix Ctrl+Alt not being treated as a substitute for AltGr anymore This issue was caused by a9c9714. --- src/terminal/adapter/ut_adapter/inputTest.cpp | 4 ++-- src/terminal/input/terminalInput.cpp | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/terminal/adapter/ut_adapter/inputTest.cpp b/src/terminal/adapter/ut_adapter/inputTest.cpp index 1df9bcc714e..406a0292c8a 100644 --- a/src/terminal/adapter/ut_adapter/inputTest.cpp +++ b/src/terminal/adapter/ut_adapter/inputTest.cpp @@ -482,7 +482,7 @@ void InputTest::TerminalInputModifierKeyTests() // Alt+Key generates [0x1b, Ctrl+key] into the stream // Pressing the control key causes all bits but the 5 least // significant ones to be zeroed out (when using ASCII). - if (AltPressed(uiKeystate) && ControlPressed(uiKeystate) && ch >= 0x40 && ch < 0x7F) + if (AltPressed(uiKeystate) && ControlPressed(uiKeystate) && ch > 0x40 && ch <= 0x5A) { s_expectedInput.clear(); s_expectedInput.push_back(L'\x1b'); @@ -491,7 +491,7 @@ void InputTest::TerminalInputModifierKeyTests() } // Alt+Key generates [0x1b, key] into the stream - if (AltPressed(uiKeystate) && ch != 0) + if (AltPressed(uiKeystate) && !ControlPressed(uiKeystate) && ch != 0) { s_expectedInput.clear(); s_expectedInput.push_back(L'\x1b'); diff --git a/src/terminal/input/terminalInput.cpp b/src/terminal/input/terminalInput.cpp index 948d2f6ad50..d77edca5d60 100644 --- a/src/terminal/input/terminalInput.cpp +++ b/src/terminal/input/terminalInput.cpp @@ -498,16 +498,16 @@ bool TerminalInput::HandleKey(const IInputEvent* const pInEvent) if (ch == UNICODE_NULL) { // For Alt+Ctrl+Key messages GetCharData() returns 0. + // The values of the ASCII characters and virtual key codes + // of , A-Z (as used below) are numerically identical. // -> Get the char from the virtual key. - ch = LOWORD(MapVirtualKeyW(keyEvent.GetVirtualKeyCode(), MAPVK_VK_TO_CHAR)); + ch = keyEvent.GetVirtualKeyCode(); } - if (ch == UNICODE_SPACE) - { - // Ctrl+@ and Ctrl+Space are supposed to send null bytes. - // -> Change Ctrl+Space to Ctrl+@ for compatibility reasons. - ch = 0x40; - } - if (ch >= 0x40 && ch < 0x7F) + // Alt+Ctrl acts as a substitute for AltGr on Windows. + // 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)) { // Pressing the control key causes all bits but the 5 least // significant ones to be zeroed out (when using ASCII). @@ -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) { _SendEscapedInputSequence(keyEvent.GetCharData()); return true; @@ -544,7 +544,7 @@ bool TerminalInput::HandleKey(const IInputEvent* const pInEvent) // -> Send a "null input sequence" in that case. // We don't need to handle other kinds of Ctrl combinations, // as we rely on the caller to pretranslate those to characters for us. - if (keyEvent.IsCtrlPressed()) + if (!keyEvent.IsAltPressed() && keyEvent.IsCtrlPressed()) { const auto ch = keyEvent.GetCharData(); const auto vkey = keyEvent.GetVirtualKeyCode();