Keyboard:
. reverted default so that ALT+TAB is not hooked (#556) . reverted default so that ALT GR's fake LCONTROL is not hooked (#558) . added new switches: -hook-alt-tab and -hook-altgr-control to support hooking these key combo's (#556)
This commit is contained in:
parent
b069614a25
commit
140d505fe9
4 changed files with 26 additions and 6 deletions
|
@ -1,6 +1,8 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
static HWND g_hFrameWindow = (HWND)0;
|
static HWND g_hFrameWindow = (HWND)0;
|
||||||
|
static bool g_bHookAltTab = false;
|
||||||
|
static bool g_bHookAltGrControl = false;
|
||||||
|
|
||||||
// NB. __stdcall (or WINAPI) and extern "C":
|
// NB. __stdcall (or WINAPI) and extern "C":
|
||||||
// . symbol is decorated as _<symbol>@bytes
|
// . symbol is decorated as _<symbol>@bytes
|
||||||
|
@ -27,13 +29,13 @@ extern "C" __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(
|
||||||
// . For: Microsoft PS/2/Win7-64, VAIO laptop/Win7-64, Microsoft USB/Win10-64
|
// . For: Microsoft PS/2/Win7-64, VAIO laptop/Win7-64, Microsoft USB/Win10-64
|
||||||
// NB. WM_KEYDOWN also includes a 9/10-bit? scanCode: LCONTROL=0x1D, RCONTROL=0x11D, RMENU=0x1D(not 0x21D)
|
// NB. WM_KEYDOWN also includes a 9/10-bit? scanCode: LCONTROL=0x1D, RCONTROL=0x11D, RMENU=0x1D(not 0x21D)
|
||||||
// . Can't suppress in app, since scanCode is not >= 0x200
|
// . Can't suppress in app, since scanCode is not >= 0x200
|
||||||
if (pKbdLlHookStruct->vkCode == VK_LCONTROL && pKbdLlHookStruct->scanCode >= 0x200) // GH#558
|
if (g_bHookAltGrControl && pKbdLlHookStruct->vkCode == VK_LCONTROL && pKbdLlHookStruct->scanCode >= 0x200) // GH#558
|
||||||
{
|
{
|
||||||
suppress = true;
|
suppress = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suppress alt-tab
|
// Suppress alt-tab
|
||||||
if (pKbdLlHookStruct->vkCode == VK_TAB && (pKbdLlHookStruct->flags & LLKHF_ALTDOWN))
|
if (g_bHookAltTab && pKbdLlHookStruct->vkCode == VK_TAB && (pKbdLlHookStruct->flags & LLKHF_ALTDOWN))
|
||||||
{
|
{
|
||||||
PostMessage(g_hFrameWindow, newMsg, VK_TAB, newlParam);
|
PostMessage(g_hFrameWindow, newMsg, VK_TAB, newlParam);
|
||||||
suppress = true;
|
suppress = true;
|
||||||
|
@ -69,7 +71,9 @@ extern "C" __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(
|
||||||
return CallNextHookEx(0/*parameter is ignored*/, nCode, wParam, lParam);
|
return CallNextHookEx(0/*parameter is ignored*/, nCode, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" __declspec(dllexport) void __cdecl RegisterHWND(HWND hWnd)
|
extern "C" __declspec(dllexport) void __cdecl RegisterHWND(HWND hWnd, bool bHookAltTab, bool bHookAltGrControl)
|
||||||
{
|
{
|
||||||
g_hFrameWindow = hWnd;
|
g_hFrameWindow = hWnd;
|
||||||
|
g_bHookAltTab = bHookAltTab;
|
||||||
|
g_bHookAltGrControl = bHookAltGrControl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,8 @@ TCHAR g_sDebugDir [MAX_PATH] = TEXT(""); // TODO: Not currently used
|
||||||
TCHAR g_sScreenShotDir[MAX_PATH] = TEXT(""); // TODO: Not currently used
|
TCHAR g_sScreenShotDir[MAX_PATH] = TEXT(""); // TODO: Not currently used
|
||||||
bool g_bCapturePrintScreenKey = true;
|
bool g_bCapturePrintScreenKey = true;
|
||||||
static bool g_bHookSystemKey = true;
|
static bool g_bHookSystemKey = true;
|
||||||
|
static bool g_bHookAltTab = false;
|
||||||
|
static bool g_bHookAltGrControl = false;
|
||||||
|
|
||||||
TCHAR g_sCurrentDir[MAX_PATH] = TEXT(""); // Also Starting Dir. Debugger uses this when load/save
|
TCHAR g_sCurrentDir[MAX_PATH] = TEXT(""); // Also Starting Dir. Debugger uses this when load/save
|
||||||
bool g_bRestart = false;
|
bool g_bRestart = false;
|
||||||
|
@ -171,6 +173,11 @@ void SetLoadedSaveStateFlag(const bool bFlag)
|
||||||
g_bLoadedSaveState = bFlag;
|
g_bLoadedSaveState = bFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GetHookAltGrControl(void)
|
||||||
|
{
|
||||||
|
return g_bHookAltGrControl;
|
||||||
|
}
|
||||||
|
|
||||||
static void ResetToLogoMode(void)
|
static void ResetToLogoMode(void)
|
||||||
{
|
{
|
||||||
g_nAppMode = MODE_LOGO;
|
g_nAppMode = MODE_LOGO;
|
||||||
|
@ -882,10 +889,10 @@ static bool HookFilterForKeyboard()
|
||||||
|
|
||||||
_ASSERT(g_hFrameWindow);
|
_ASSERT(g_hFrameWindow);
|
||||||
|
|
||||||
typedef void (*RegisterHWNDProc)(HWND);
|
typedef void (*RegisterHWNDProc)(HWND, bool, bool);
|
||||||
RegisterHWNDProc RegisterHWND = (RegisterHWNDProc) GetProcAddress(g_hinstDLL, "RegisterHWND");
|
RegisterHWNDProc RegisterHWND = (RegisterHWNDProc) GetProcAddress(g_hinstDLL, "RegisterHWND");
|
||||||
if (RegisterHWND)
|
if (RegisterHWND)
|
||||||
RegisterHWND(g_hFrameWindow);
|
RegisterHWND(g_hFrameWindow, g_bHookAltTab, g_bHookAltGrControl);
|
||||||
|
|
||||||
HOOKPROC hkprcLowLevelKeyboardProc = (HOOKPROC) GetProcAddress(g_hinstDLL, "LowLevelKeyboardProc");
|
HOOKPROC hkprcLowLevelKeyboardProc = (HOOKPROC) GetProcAddress(g_hinstDLL, "LowLevelKeyboardProc");
|
||||||
|
|
||||||
|
@ -1294,6 +1301,14 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int)
|
||||||
{
|
{
|
||||||
g_bHookSystemKey = false;
|
g_bHookSystemKey = false;
|
||||||
}
|
}
|
||||||
|
else if (strcmp(lpCmdLine, "-hook-alt-tab") == 0) // GH#556
|
||||||
|
{
|
||||||
|
g_bHookAltTab = true;
|
||||||
|
}
|
||||||
|
else if (strcmp(lpCmdLine, "-hook-altgr-control") == 0) // GH#556
|
||||||
|
{
|
||||||
|
g_bHookAltGrControl = true;
|
||||||
|
}
|
||||||
else if (strcmp(lpCmdLine, "-spkr-inc") == 0)
|
else if (strcmp(lpCmdLine, "-spkr-inc") == 0)
|
||||||
{
|
{
|
||||||
lpCmdLine = GetCurrArg(lpNextArg);
|
lpCmdLine = GetCurrArg(lpNextArg);
|
||||||
|
|
|
@ -30,6 +30,7 @@ extern HINSTANCE g_hInstance;
|
||||||
extern AppMode_e g_nAppMode;
|
extern AppMode_e g_nAppMode;
|
||||||
bool GetLoadedSaveStateFlag(void);
|
bool GetLoadedSaveStateFlag(void);
|
||||||
void SetLoadedSaveStateFlag(const bool bFlag);
|
void SetLoadedSaveStateFlag(const bool bFlag);
|
||||||
|
bool GetHookAltGrControl(void);
|
||||||
|
|
||||||
extern TCHAR g_sProgramDir[MAX_PATH];
|
extern TCHAR g_sProgramDir[MAX_PATH];
|
||||||
extern TCHAR g_sCurrentDir[MAX_PATH];
|
extern TCHAR g_sCurrentDir[MAX_PATH];
|
||||||
|
|
|
@ -319,7 +319,7 @@ void KeybQueueKeypress (WPARAM key, Keystroke_e bASCII)
|
||||||
{
|
{
|
||||||
if ( (GetKeyState(VK_SHIFT) >= 0) && !g_bCapsLock )
|
if ( (GetKeyState(VK_SHIFT) >= 0) && !g_bCapsLock )
|
||||||
newKey += 'a' - 'A'; // convert to lowercase key
|
newKey += 'a' - 'A'; // convert to lowercase key
|
||||||
else if (GetKeyState(VK_CONTROL) < 0)
|
else if (GetHookAltGrControl() && GetKeyState(VK_CONTROL) < 0)
|
||||||
newKey -= 'A' - 1; // convert to control-key
|
newKey -= 'A' - 1; // convert to control-key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue