1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x0500
#pragma comment(lib, "user32.lib")
#include <windows.h>
#include <stdio.h>
HHOOK hLowlevelProc;
bool breaked = false;
unsigned char keys[2] = { VK_LWIN, VK_TAB };
void SendKey()
{
INPUT input[4];
for (int i = 0; i <= 1; i++)
{
input[i].type = INPUT_KEYBOARD;
input[i].ki.wVk = keys[i];
input[i].ki.dwFlags = 0;
}
SendInput(2, input, sizeof(INPUT));
for (int i = 0; i <= 1; i++)
{
input[i].ki.dwFlags = KEYEVENTF_KEYUP;
}
SendInput(2, input, sizeof(INPUT));
}
LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MOUSEHOOKSTRUCT * pMouseStruct = (MOUSEHOOKSTRUCT *) lParam;
if (pMouseStruct != NULL)
{
if (pMouseStruct->pt.x <= 10 && pMouseStruct->pt.y <= 10 && breaked == false) {
SetForegroundWindow(GetConsoleWindow());
SendKey();
breaked = true;
}
else if (pMouseStruct->pt.x > 10 && pMouseStruct->pt.y > 10 && breaked)
{
breaked = false;
}
printf("Mouse position X = %d Mouse Position Y = %d\n", pMouseStruct->pt.x, pMouseStruct->pt.y);
}
return CallNextHookEx(hLowlevelProc, nCode, wParam, lParam);
}
void MessageLoop()
{
MSG message;
while (GetMessage(&message, NULL, 0, 0) > 0)
{
TranslateMessage(&message);
DispatchMessage(&message);
}
}
DWORD WINAPI MouseDetect(LPVOID lpParm)
{
HINSTANCE hInstance = GetModuleHandle(NULL);
if (!hInstance)
{
return 1;
}
hLowlevelProc = SetWindowsHookEx(
WH_MOUSE_LL,
(HOOKPROC)LowLevelMouseProc,
hInstance,
NULL
);
MessageLoop();
UnhookWindowsHookEx(hLowlevelProc);
return 0;
}
int main(int argc, char** argv)
{
//ShowWindow(GetConsoleWindow(), SW_HIDE);
HANDLE hThread;
DWORD dwThread;
hThread = CreateThread(
NULL,
NULL,
(LPTHREAD_START_ROUTINE)MouseDetect,
(LPVOID)argv[0],
NULL,
&dwThread
);
if (hThread)
{
return WaitForSingleObject(hThread, INFINITE);
}
else
{
return 1;
}
}
|