Skip to content

Commit

Permalink
Merge pull request #263 from dqhieuu/master
Browse files Browse the repository at this point in the history
[Win] Reliably check caps lock for every key press
  • Loading branch information
tuyenvm authored Aug 22, 2024
2 parents db31c52 + d6bd4fa commit 0889965
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Sources/OpenKey/win32/OpenKey/OpenKey/OpenKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,16 @@ static void handleMacro() {
}

static bool SetModifierMask(const Uint16& vkCode) {
// For caps lock case, toggling the flag isn't enough. We need to check the actual state, which should be done before each key press.
// Example: the caps lock state can be changed without the key being pressed, or the key toggle is made with admin privilege, making the app not able to detect the change.
if (GetKeyState(VK_CAPITAL) == 1) _flag |= MASK_CAPITAL;
else _flag &= ~MASK_CAPITAL;

if (vkCode == VK_LSHIFT || vkCode == VK_RSHIFT) _flag |= MASK_SHIFT;
else if (vkCode == VK_LCONTROL || vkCode == VK_RCONTROL) _flag |= MASK_CONTROL;
else if (vkCode == VK_LMENU || vkCode == VK_RMENU) _flag |= MASK_ALT;
else if (vkCode == VK_LWIN || vkCode == VK_RWIN) _flag |= MASK_WIN;
else if (vkCode == VK_NUMLOCK) _flag |= MASK_NUMLOCK;
else if (vkCode == VK_CAPITAL) _flag ^= MASK_CAPITAL;
else if (vkCode == VK_SCROLL) _flag |= MASK_SCROLL;
else {
_isFlagKey = false;
Expand Down

0 comments on commit 0889965

Please sign in to comment.