diff --git a/windows/src/engine/keyman32/kmhook_getmessage.cpp b/windows/src/engine/keyman32/kmhook_getmessage.cpp index 4efd4879463..f000c2661e7 100644 --- a/windows/src/engine/keyman32/kmhook_getmessage.cpp +++ b/windows/src/engine/keyman32/kmhook_getmessage.cpp @@ -68,7 +68,7 @@ void ProcessWMKeymanControlInternal(HWND hwnd, WPARAM wParam, LPARAM lParam); void ProcessWMKeymanControl(WPARAM wParam, LPARAM lParam); void ProcessWMKeyman(HWND hwnd, WPARAM wParam, LPARAM lParam); -void GetCapsAndNumlockState(); +void RefreshModifierState(); /* BOOL SysTabCtrl(HWND hwnd) @@ -354,7 +354,7 @@ void ProcessWMKeyman(HWND hwnd, WPARAM wParam, LPARAM lParam) if(IsFocusedThread()) { if(_td->app) _td->app->ResetQueue(); - GetCapsAndNumlockState(); + RefreshModifierState(); UpdateActiveWindows(); } } @@ -409,14 +409,17 @@ ProcessWMKeymanControl(WPARAM wParam, LPARAM lParam) { } } -/* - GetCapsAndNumlockState: - - Updates the global caps and numlock state when a window is focused, because it - may have been reset while Keyman was not aware of it -*/ -void GetCapsAndNumlockState() { // I4793 - DWORD n = Globals::get_ShiftState(); +/** + * Refresh Keyman's internal keyboard modifier and toggle state according + * to the Windows current keyboard state (not async state). The state may + * have been reset while Keyman was not aware of it. This is used only when + * focus changes. Note that the global values are per-architecture, so + * these may track separately. + * + * @see ProcessModifierChange() + */ +void RefreshModifierState() { // I4793 + DWORD previousShiftState = Globals::get_ShiftState(); RefreshToggleState(); @@ -435,18 +438,19 @@ void GetCapsAndNumlockState() { // I4793 if(GetKeyState(VK_RMENU) < 0) *Globals::ShiftState() |= RALTFLAG; else *Globals::ShiftState() &= ~RALTFLAG; - SendDebugMessageFormat("Enter: %x Exit: %x", n, Globals::get_ShiftState()); + SendDebugMessageFormat("Enter: %x Exit: %x", previousShiftState, Globals::get_ShiftState()); } -/* - Update the Keyman shift state based on the key event. This has to be - done from both the GetMessage hook and the TSF methods, because we don't - consistently receive modifier events in some applications (e.g. ALT in Firefox) - via TSF, and we don't receive the notifications via the GetMessage hook when - in UWP apps (#4369). - - TODO: test whether we still need the GetMessage hook for reading modifier state. -*/ +/** + * Update the Keyman shift state based on the key event. This has to be done + * from both the GetMessage hook and the TSF methods, because we don't + * consistently receive modifier events in some applications (e.g. ALT in + * Firefox) via TSF, and we don't receive the notifications via the GetMessage + * hook when in UWP apps (#4369). + * + * TODO: test whether we still need the GetMessage hook for reading modifier + * state. + */ void ProcessModifierChange(UINT key, BOOL isUp, BOOL isExtended) { // I4793 UINT flag = 0;