Skip to content

Commit

Permalink
Windows: fix handling AltGr+Key
Browse files Browse the repository at this point in the history
  • Loading branch information
magiblot committed Oct 21, 2024
1 parent c1abb10 commit bfca212
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
12 changes: 7 additions & 5 deletions source/platform/win32con.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,15 @@ bool getWin32Key(const KEY_EVENT_RECORD &KeyEvent, TEvent &ev, InputState &state
ev.keyDown.keyCode == 0x3A00 )
// Discard standalone Shift, Ctrl, Alt, Caps Lock keys.
ev.keyDown.keyCode = kbNoKey;
else if ( (ev.keyDown.controlKeyState & kbCtrlShift) &&
(ev.keyDown.controlKeyState & kbAltShift) ) // Ctrl+Alt is AltGr.
else if (ev.keyDown.controlKeyState & kbRightAlt)
{
// When AltGr+Key does not produce a character, a
// keyCode with unwanted effects may be read instead.
if (!ev.keyDown.textLength)
if (ev.keyDown.textLength == 0)
// When AltGr+Key does not produce a character, an unwanted keyCode
// may be read instead, so discard it.
ev.keyDown.keyCode = kbNoKey;
else
// Otherwise, discard the Ctrl modifier that is automatically added.
ev.keyDown.controlKeyState &= ~kbLeftCtrl;
}
else if (KeyEvent.wVirtualScanCode < 89)
{
Expand Down
12 changes: 7 additions & 5 deletions source/tvision/hardwrvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,15 @@ BOOL THardwareInfo::getKeyEvent( TEvent& event )
event.keyDown.keyCode == 0x3A00 )
// Discard standalone Shift, Ctrl, Alt, Caps Lock keys.
event.keyDown.keyCode = kbNoKey;
else if( (event.keyDown.controlKeyState & kbCtrlShift) &&
(event.keyDown.controlKeyState & kbAltShift) ) // Ctrl+Alt is AltGr.
else if( event.keyDown.controlKeyState & kbRightAlt )
{
// When AltGr+Key does not produce a character, a
// keyCode with unwanted effects may be read instead.
if( !event.keyDown.charScan.charCode )
if( event.keyDown.charScan.charCode == '\0' )
// When AltGr+Key does not produce a character, an unwanted keyCode
// may be read instead, so discard it.
event.keyDown.keyCode = kbNoKey;
else
// Otherwise, discard the Ctrl modifier that is automatically added.
event.keyDown.controlKeyState &= ~kbLeftCtrl;
}
else if( irBuffer.Event.KeyEvent.wVirtualScanCode < 89 )
{
Expand Down
4 changes: 2 additions & 2 deletions test/platform/far2l.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ TEST(Far2l, ShouldReadFar2lInput)
{"AQC+AAAAAAAAAKwgAABL\x07", {Accepted, keyDownEv(kbNoKey, 0x0000, "")}},
{"AQBWAAAACAAAAAAAAABL\x07", {Accepted, keyDownEv(kbCtrlV, kbLeftCtrl, "")}},
{"AQA5AAAACAAAADkAAABL\x07", {Accepted, keyDownEv(kb9, kbLeftCtrl, "9")}},
{"AQBWAAAACgAAAFYAAABL\x07", {Accepted, keyDownEv(kbAltV, kbLeftCtrl | kbLeftAlt, "")}},
{"AQBWAAAACgAAAAAAAABL\x07", {Ignored}}, // AltGr + V, UnicodeChar = 0
{"AQBWAAAACgAAAFYAAABL\x07", {Accepted, keyDownEv(kbAltV, kbLeftCtrl | kbLeftAlt, "")}}, // UnicodeChar = 'V'
{"AQBWAAAACgAAAAAAAABL\x07", {Accepted, keyDownEv(kbAltV, kbLeftCtrl | kbLeftAlt, "")}}, // UnicodeChar = 0
{"AQAMAAAAIgAAAAAAAABL\x07", {Ignored}}, // Alt + VK_CLEAR
{"AAAGAAAAAAAAAAAAAQAAAE0=\x07", {Accepted, mouseEv({0, 6}, meMouseMoved, 0, 0, 0)}},
{"CQANAAQAAAAAAAAAAAAAAE0=\x07", {Accepted, mouseEv({9, 13}, 0, 0, mbMiddleButton, 0)}},
Expand Down

0 comments on commit bfca212

Please sign in to comment.