我正在尝试将SetWindowsHookExA()与WH_MOUSE_LL一起使用,以准备注入的低级鼠标单击。
这是我的钩子代码。
DWORD dwThreadMain; // The process main thread. (Already have this)
HWND mainWindow; // Already have this pointer
MSG hMsg;
MouseHOOK = SetWindowsHookExA(WH_MOUSE_LL, MouseHookProc, NULL, dwThreadMain);
if (!MouseHOOK) {
// Cant't Hook
}
KeyBoardHOOK = SetWindowsHookExA(WH_KEYBOARD_LL, KeyBoardHookProc, NULL, dwThreadMain);
if (!KeyBoardHOOK) {
// Cant't HOOK
}
while (GetMessage(&hMsg, mainWindow, 0, 0)) {
TranslateMessage(&hMsg);
DispatchMessage(&hMsg);
}
这是我的MouseHookProc和KeyBoardHookProc:
LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HC_ACTION) {
if (wParam == WM_RBUTTONUP || wParam == WM_RBUTTONDOWN
|| wParam == WM_LBUTTONUP || wParam == WM_LBUTTONDOWN) {
MSLLHOOKSTRUCT* hookStruct = (MSLLHOOKSTRUCT*)lParam;
if ((hookStruct->flags & LLMHF_INJECTED) == LLMHF_INJECTED) {
MessageBoxA(NULL, "MOUSE INJECTED!", "POOR MOUSE", MB_OK);
return TRUE;
}
if ((hookStruct->flags & LLMHF_LOWER_IL_INJECTED) == LLMHF_LOWER_IL_INJECTED) {
MessageBoxA(NULL, "MOUSE INJECTED!", "POOR MOUSE", MB_OK);
return TRUE;
}
}
}
return CallNextHookEx(MouseHOOK, nCode, wParam, lParam);
}
LRESULT CALLBACK KeyBoardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HC_ACTION) {
if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) {
KBDLLHOOKSTRUCT* hookStruct = (KBDLLHOOKSTRUCT*)lParam;
if ((hookStruct->flags & LLKHF_INJECTED) == LLKHF_INJECTED) {
MessageBoxA(NULL, "KEYBOARD INJECTED!", "POOR KEYBOARD", MB_OK);
return TRUE;
}
if ((hookStruct->flags & LLKHF_LOWER_IL_INJECTED) == LLKHF_LOWER_IL_INJECTED) {
MessageBoxA(NULL, "KEYBOARD INJECTED!", "POOR KEYBOARD", MB_OK);
return TRUE;
}
}
}
return CallNextHookEx(KeyBoardHOOK, nCode, wParam, lParam);
}
这里的问题不在挂钩上,当注入标记在那里时,消息框显示出来。键盘会阻止输入。但是只有在鼠标中,“返回TRUE”不会阻止点击被处理。
我认为我错过了一些东西...还有另一种方法吗?