mirror of
https://github.com/AppleWin/AppleWin.git
synced 2024-12-23 00:30:17 +00:00
Hook system keys: (#556)
. added -no-hook-system-key to prevent hooking system keys . updated help . HookFilter.dll: changed to directly send virtual key code
This commit is contained in:
parent
734bc4cee2
commit
51669f36f3
@ -20,28 +20,24 @@ extern "C" __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(
|
||||
UINT newMsg = pKbdLlHookStruct->flags & LLKHF_UP ? WM_KEYUP : WM_KEYDOWN;
|
||||
LPARAM newlParam = newMsg == WM_KEYUP ? 3<<30 : 0; // b31:transition state, b30:previous key state
|
||||
|
||||
// Note about PostMessage() and use of VkKeyScan():
|
||||
// . Convert the ascii code to virtual key code, so that the message pump can do TranslateMessage()
|
||||
// . NB. From MSDN for "WM_KEYDOWN" && "WM_KEYUP" : "Applications must pass wParam to TranslateMessage without altering it at all."
|
||||
|
||||
// Suppress alt-tab
|
||||
if (pKbdLlHookStruct->vkCode == VK_TAB && (pKbdLlHookStruct->flags & LLKHF_ALTDOWN))
|
||||
{
|
||||
PostMessage(g_hFrameWindow, newMsg, LOBYTE(VkKeyScan(0x09)), newlParam);
|
||||
PostMessage(g_hFrameWindow, newMsg, VK_TAB, newlParam);
|
||||
suppress = true;
|
||||
}
|
||||
|
||||
// Suppress alt-escape
|
||||
if (pKbdLlHookStruct->vkCode == VK_ESCAPE && (pKbdLlHookStruct->flags & LLKHF_ALTDOWN))
|
||||
{
|
||||
PostMessage(g_hFrameWindow, newMsg, LOBYTE(VkKeyScan(0x1B)), newlParam);
|
||||
PostMessage(g_hFrameWindow, newMsg, VK_ESCAPE, newlParam);
|
||||
suppress = true;
|
||||
}
|
||||
|
||||
// Suppress alt-space
|
||||
if (pKbdLlHookStruct->vkCode == VK_SPACE && (pKbdLlHookStruct->flags & LLKHF_ALTDOWN))
|
||||
{
|
||||
PostMessage(g_hFrameWindow, newMsg, LOBYTE(VkKeyScan(0x20)), newlParam);
|
||||
PostMessage(g_hFrameWindow, newMsg, VK_SPACE, newlParam);
|
||||
suppress = true;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,8 @@
|
||||
Enable the dialog box to display the last file saved to<br><br>
|
||||
-no-printscreen-key<br>
|
||||
Prevent the PrintScreen key from being registered<br><br>
|
||||
-no-hook-system-key<br>
|
||||
Prevent certain system key combinations from being hooked (to prevent the emulator from trapping ALT+ESC, ALT+SPACE, ALT+TAB and CTRL+ESC). This means that the equivalent Open Apple+<key> combinations won't work within the emulator.<br><br>
|
||||
-use-real-printer<br>
|
||||
Enables Advanced configuration control to allow dumping to a real printer<br><br>
|
||||
-noreg<br>
|
||||
|
@ -78,6 +78,8 @@ TCHAR g_sProgramDir[MAX_PATH] = TEXT(""); // Directory of where AppleWin exe
|
||||
TCHAR g_sDebugDir [MAX_PATH] = TEXT(""); // TODO: Not currently used
|
||||
TCHAR g_sScreenShotDir[MAX_PATH] = TEXT(""); // TODO: Not currently used
|
||||
bool g_bCapturePrintScreenKey = true;
|
||||
static bool g_bHookSystemKey = true;
|
||||
|
||||
TCHAR g_sCurrentDir[MAX_PATH] = TEXT(""); // Also Starting Dir. Debugger uses this when load/save
|
||||
bool g_bRestart = false;
|
||||
bool g_bRestartFullScreen = false;
|
||||
@ -871,7 +873,7 @@ static HINSTANCE g_hinstDLL = 0;
|
||||
static HHOOK g_hhook = 0;
|
||||
|
||||
// Pre: g_hFrameWindow must be valid
|
||||
void HookFilterForKeyboard()
|
||||
bool HookFilterForKeyboard()
|
||||
{
|
||||
g_hinstDLL = LoadLibrary(TEXT("HookFilter.dll"));
|
||||
|
||||
@ -890,16 +892,17 @@ void HookFilterForKeyboard()
|
||||
g_hinstDLL,
|
||||
0);
|
||||
|
||||
if (g_hhook == 0 || g_hFrameWindow == 0)
|
||||
{
|
||||
std::string msg("Failed to install hook filter for system keys");
|
||||
if (g_hhook != 0 && g_hFrameWindow != 0)
|
||||
return true;
|
||||
|
||||
DWORD dwErr = GetLastError();
|
||||
MessageBox(GetDesktopWindow(), msg.c_str(), "Warning", MB_ICONASTERISK | MB_OK);
|
||||
std::string msg("Failed to install hook filter for system keys");
|
||||
|
||||
msg += "\n";
|
||||
LogFileOutput(msg.c_str());
|
||||
}
|
||||
DWORD dwErr = GetLastError();
|
||||
MessageBox(GetDesktopWindow(), msg.c_str(), "Warning", MB_ICONASTERISK | MB_OK);
|
||||
|
||||
msg += "\n";
|
||||
LogFileOutput(msg.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
void UnhookFilterForKeyboard()
|
||||
@ -1227,6 +1230,10 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int)
|
||||
{
|
||||
g_bShowPrintScreenWarningDialog = false;
|
||||
}
|
||||
else if (strcmp(lpCmdLine, "-no-hook-system-key") == 0) // Don't hook the System keys (eg. Left-ALT+ESC/SPACE/TAB) GH#556
|
||||
{
|
||||
g_bHookSystemKey = false;
|
||||
}
|
||||
else if (strcmp(lpCmdLine, "-spkr-inc") == 0)
|
||||
{
|
||||
lpCmdLine = GetCurrArg(lpNextArg);
|
||||
@ -1419,7 +1426,11 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int)
|
||||
LogFileOutput("Main: RegisterHotKeys()\n");
|
||||
}
|
||||
|
||||
HookFilterForKeyboard(); // needs valid g_hFrameWindow (for message pump)
|
||||
if (g_bHookSystemKey)
|
||||
{
|
||||
if (HookFilterForKeyboard()) // needs valid g_hFrameWindow (for message pump)
|
||||
LogFileOutput("Main: HookFilterForKeyboard()\n");
|
||||
}
|
||||
|
||||
// Need to test if it's safe to call ResetMachineState(). In the meantime, just call DiskReset():
|
||||
DiskReset(); // Switch from a booting A][+ to a non-autostart A][, so need to turn off floppy motor
|
||||
@ -1527,7 +1538,11 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int)
|
||||
DSUninit();
|
||||
LogFileOutput("Main: DSUninit()\n");
|
||||
|
||||
UnhookFilterForKeyboard();
|
||||
if (g_bHookSystemKey)
|
||||
{
|
||||
UnhookFilterForKeyboard();
|
||||
LogFileOutput("Main: UnhookFilterForKeyboard()\n");
|
||||
}
|
||||
}
|
||||
while (g_bRestart);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user