Skip to content

Commit

Permalink
Fix Ctrl+Alt not being treated as a substitute for AltGr anymore (#5552)
Browse files Browse the repository at this point in the history
This PR fixes #5525 by re-adding range checks that were erroneously removed in
a9c9714.

## 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 `|`, `~`, `{`, `[`, `]`, `}`

Closes #5525
  • Loading branch information
lhecker authored Apr 28, 2020
1 parent e358b96 commit 9247ff0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/terminal/adapter/ut_adapter/inputTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down
20 changes: 10 additions & 10 deletions src/terminal/input/terminalInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Space>, 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).
Expand All @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit 9247ff0

Please sign in to comment.