SysKey hook filter:

. Fix for GetKeyState() not detecting the special keys as being up (so AKD was erroneously reporting the key still down).
. eg. Whilst pressing TAB, press LEFT ALT, then release TAB.
This commit is contained in:
tomcw 2018-05-28 22:13:54 +01:00
parent 6b53adde55
commit 0d4be07e7e
3 changed files with 25 additions and 33 deletions

View File

@ -1260,7 +1260,7 @@ LRESULT CALLBACK FrameWndProc (
case WM_KEYDOWN:
KeybUpdateCtrlShiftStatus();
KeybSpecialKeydown(wparam);
KeybSpecialKeyTransition(WM_KEYDOWN, wparam);
// Process is done in WM_KEYUP: VK_F1 VK_F2 VK_F3 VK_F4 VK_F5 VK_F6 VK_F7 VK_F8
if ((wparam >= VK_F1) && (wparam <= VK_F8) && (buttondown == -1))
@ -1400,7 +1400,14 @@ LRESULT CALLBACK FrameWndProc (
break;
case WM_KEYUP:
KeybSpecialKeyup(wparam);
KeybSpecialKeyTransition(WM_KEYUP, wparam);
if (wparam == VK_ESCAPE || wparam == VK_SPACE || wparam == VK_TAB)
{
char str[40];
sprintf(str, "WM_KEYUP: %d\n", wparam);
OutputDebugString(str);
}
// Process is done in WM_KEYUP: VK_F1 VK_F2 VK_F3 VK_F4 VK_F5 VK_F6 VK_F7 VK_F8
if ((wparam >= VK_F1) && (wparam <= VK_F8) && (buttondown == (int)wparam-VK_F1))

View File

@ -390,53 +390,39 @@ static char ClipboardCurrChar(bool bIncPtr)
//===========================================================================
// For AKD (Any Key Down), need special handling for the hooked key combos(*), as GetKeyState() doesn't detect the keys as being down.
// . And equally GetKeyState() doesn't detect the keys as being up: eg. Whilst pressing TAB, press LEFT ALT, then release TAB.
// (*) ALT+TAB, ALT+ESCAPE, ALT+SPACE
static enum {AKD_TAB=0, AKD_ESCAPE, AKD_SPACE};
static bool g_specialAKD[3] = {false,false,false};
void KeybSpecialKeydown(DWORD wparam)
void KeybSpecialKeyTransition(UINT message, WPARAM wparam)
{
_ASSERT(message == WM_KEYUP || message == WM_KEYDOWN);
bool bState = message == WM_KEYDOWN;
switch (wparam)
{
case VK_TAB:
g_specialAKD[AKD_TAB] = true;
g_specialAKD[AKD_TAB] = bState;
break;
case VK_ESCAPE:
g_specialAKD[AKD_ESCAPE] = true;
g_specialAKD[AKD_ESCAPE] = bState;
break;
case VK_SPACE:
g_specialAKD[AKD_SPACE] = true;
g_specialAKD[AKD_SPACE] = bState;
break;
};
}
void KeybSpecialKeyup(DWORD wparam)
{
switch (wparam)
{
case VK_TAB:
g_specialAKD[AKD_TAB] = false;
break;
case VK_ESCAPE:
g_specialAKD[AKD_ESCAPE] = false;
break;
case VK_SPACE:
g_specialAKD[AKD_SPACE] = false;
break;
};
}
static bool IsSpecialAKD(int lastvirtkey)
static void GetKeyStateOfSpecialAKD(int lastvirtkey, bool& bState)
{
if (VK_TAB == lastvirtkey)
return g_specialAKD[AKD_TAB];
bState = g_specialAKD[AKD_TAB];
else if (VK_ESCAPE == lastvirtkey)
return g_specialAKD[AKD_ESCAPE];
bState = g_specialAKD[AKD_ESCAPE];
else if (VK_SPACE == lastvirtkey)
return g_specialAKD[AKD_SPACE];
return false;
bState = g_specialAKD[AKD_SPACE];
}
//===========================================================================
@ -480,10 +466,10 @@ BYTE __stdcall KeybReadFlag (WORD, WORD, BYTE, BYTE, ULONG)
keywaiting = 0;
if (IsSpecialAKD(lastvirtkey))
return keycode | 0x80;
bool bState = GetKeyState(lastvirtkey) < 0;
GetKeyStateOfSpecialAKD(lastvirtkey, bState);
return keycode | ((GetKeyState(lastvirtkey) < 0) ? 0x80 : 0);
return keycode | (bState ? 0x80 : 0);
}
//===========================================================================

View File

@ -14,8 +14,7 @@ BYTE KeybGetKeycode ();
void KeybQueueKeypress (int,BOOL);
void KeybToggleCapsLock ();
void KeybToggleP8ACapsLock ();
void KeybSpecialKeydown(DWORD wparam);
void KeybSpecialKeyup(DWORD wparam);
void KeybSpecialKeyTransition(UINT message, WPARAM wparam);
void KeybSetSnapshot_v1(const BYTE LastKey);
void KeybSaveSnapshot(class YamlSaveHelper& yamlSaveHelper);
void KeybLoadSnapshot(class YamlLoadHelper& yamlLoadHelper);