#3044 Stopped attach hook thread to foreground
This commit is contained in:
parent
9caa04237c
commit
18c2c90144
|
@ -120,7 +120,6 @@ static LPARAM g_deadLParam = 0;
|
||||||
static BYTE g_deadKeyState[256] = { 0 };
|
static BYTE g_deadKeyState[256] = { 0 };
|
||||||
static BYTE g_keyState[256] = { 0 };
|
static BYTE g_keyState[256] = { 0 };
|
||||||
static DWORD g_hookThread = 0;
|
static DWORD g_hookThread = 0;
|
||||||
static DWORD g_attachedThread = 0;
|
|
||||||
static bool g_fakeInput = false;
|
static bool g_fakeInput = false;
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
@ -136,53 +135,6 @@ int _fltused=0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// internal functions
|
|
||||||
//
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
detachThread()
|
|
||||||
{
|
|
||||||
if (g_attachedThread != 0 && g_hookThread != g_attachedThread) {
|
|
||||||
AttachThreadInput(g_hookThread, g_attachedThread, FALSE);
|
|
||||||
g_attachedThread = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
|
||||||
bool
|
|
||||||
attachThreadToForeground()
|
|
||||||
{
|
|
||||||
// only attach threads if using low level hooks. a low level hook
|
|
||||||
// runs in the thread that installed the hook but we have to make
|
|
||||||
// changes that require being attached to the target thread (which
|
|
||||||
// should be the foreground window). a regular hook runs in the
|
|
||||||
// thread that just removed the event from its queue so we're
|
|
||||||
// already in the right thread.
|
|
||||||
if (g_hookThread != 0) {
|
|
||||||
HWND window = GetForegroundWindow();
|
|
||||||
if (window == NULL)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
DWORD threadID = GetWindowThreadProcessId(window, NULL);
|
|
||||||
// skip if no change
|
|
||||||
if (g_attachedThread != threadID) {
|
|
||||||
// detach from previous thread
|
|
||||||
detachThread();
|
|
||||||
|
|
||||||
// attach to new thread
|
|
||||||
if (threadID != 0 && threadID != g_hookThread) {
|
|
||||||
AttachThreadInput(g_hookThread, threadID, TRUE);
|
|
||||||
g_attachedThread = threadID;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !NO_GRAB_KEYBOARD
|
#if !NO_GRAB_KEYBOARD
|
||||||
static
|
static
|
||||||
WPARAM
|
WPARAM
|
||||||
|
@ -497,7 +449,6 @@ static
|
||||||
bool
|
bool
|
||||||
keyboardHookHandler(WPARAM wParam, LPARAM lParam)
|
keyboardHookHandler(WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
attachThreadToForeground();
|
|
||||||
return doKeyboardHookHandler(wParam, lParam);
|
return doKeyboardHookHandler(wParam, lParam);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -608,7 +559,6 @@ static
|
||||||
bool
|
bool
|
||||||
mouseHookHandler(WPARAM wParam, SInt32 x, SInt32 y, SInt32 data)
|
mouseHookHandler(WPARAM wParam, SInt32 x, SInt32 y, SInt32 data)
|
||||||
{
|
{
|
||||||
// attachThreadToForeground();
|
|
||||||
return doMouseHookHandler(wParam, x, y, data);
|
return doMouseHookHandler(wParam, x, y, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1080,9 +1030,6 @@ uninstall(void)
|
||||||
g_deadVirtKey = 0;
|
g_deadVirtKey = 0;
|
||||||
g_deadLParam = 0;
|
g_deadLParam = 0;
|
||||||
|
|
||||||
// detach from thread
|
|
||||||
detachThread();
|
|
||||||
|
|
||||||
// uninstall hooks
|
// uninstall hooks
|
||||||
if (g_keyboardLL != NULL) {
|
if (g_keyboardLL != NULL) {
|
||||||
UnhookWindowsHookEx(g_keyboardLL);
|
UnhookWindowsHookEx(g_keyboardLL);
|
||||||
|
|
Loading…
Reference in New Issue