Skip to content

Commit 0f75538

Browse files
committed
Improve AltGr modifier triggering detection
A press/release of AltGr is translated by the system into the press/release of two keys - LCtrl and RAlt. In Far, for modifiers, activation is registered upon release, and the problem with AltGr is that, being a combined event, it triggered upon the release of the very first key in the combination - LCtrl, thereby producing "CtrlRAlt" instead of the expected "RAlt" (similarly for compound combinations). This patch prevents premature reaction to the LCtrl release event.
1 parent 70b89ea commit 0f75538

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

far/keyboard.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ enum MODIF_PRESSED_LAST
101101
MODIF_CTRL = 3_bit,
102102
MODIF_RCTRL = 4_bit,
103103
};
104-
static bool LastWasDown;
104+
static bool LastWasDown, LastWasAltGr;
105105

106106
static std::chrono::steady_clock::time_point KeyPressedLastTime;
107107

@@ -1116,6 +1116,7 @@ static DWORD GetInputRecordImpl(INPUT_RECORD *rec,bool ExcludeMacro,bool Process
11161116
{
11171117
const auto CtrlState = rec->Event.KeyEvent.dwControlKeyState;
11181118
const auto KeyCode = rec->Event.KeyEvent.wVirtualKeyCode;
1119+
const auto KeyDown = rec->Event.KeyEvent.bKeyDown;
11191120

11201121
UpdateIntKeyState(CtrlState);
11211122

@@ -1127,10 +1128,15 @@ static DWORD GetInputRecordImpl(INPUT_RECORD *rec,bool ExcludeMacro,bool Process
11271128
true :
11281129
(CtrlState & SHIFT_PRESSED) != 0;
11291130

1130-
if (!rec->Event.KeyEvent.bKeyDown && CalcKey != KEY_NONE && !LastWasDown)
1131+
if (!KeyDown && CalcKey != KEY_NONE && !LastWasDown)
11311132
CalcKey = KEY_NONE;
11321133

1133-
LastWasDown = rec->Event.KeyEvent.bKeyDown;
1134+
if (LastWasAltGr && !KeyDown && KeyCode == VK_CONTROL && !(CtrlState & ENHANCED_KEY))
1135+
CalcKey = KEY_NONE;
1136+
else
1137+
LastWasDown = KeyDown;
1138+
1139+
LastWasAltGr = KeyCode==VK_MENU && ENHANCED_KEY == (CtrlState & (ENHANCED_KEY | LEFT_CTRL_PRESSED));
11341140

11351141
Panel::EndDrag();
11361142
}

0 commit comments

Comments
 (0)