Код: Выбрать все
// ConsoleApplication1.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//
#include "pch.h"
#include <iostream>
#include <fstream>
#define _WIN32_WINNT 0x0400
#pragma comment( lib, "user32.lib" )
#include <windows.h>
#include <stdio.h>
HHOOK hMouseHook;
using namespace std;
LRESULT CALLBACK mouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
ofstream f;
string filename = "//Gansta-girs//net//huycord333.txt";
MOUSEHOOKSTRUCT * pMouseStruct = (MOUSEHOOKSTRUCT *)lParam;
if (pMouseStruct != NULL) {
if (wParam == WM_LBUTTONDOWN)
{
printf("Lclicked");
f.open(filename, ios::out);
f << "X=" << pMouseStruct->pt.x << ";" << "Y=" << pMouseStruct->pt.y << ";" << "btn=LClicked" << endl;
f.close();
////Sleep(10000);
}
if (wParam == WM_RBUTTONDOWN)
{
printf("Rclicked");
f.open(filename, ios::out);
f << "X=" << pMouseStruct->pt.x << ";" << "Y=" << pMouseStruct->pt.y << ";" << "btn=RClicked" << endl;
f.close();
}
printf("Mouse position X = %d Mouse Position Y = %d\n", pMouseStruct->pt.x, pMouseStruct->pt.y);
f.open(filename, ios::out);
f << "X=" << pMouseStruct->pt.x << ";" << "Y=" << pMouseStruct->pt.y << ";" << endl;
f.close();
}
return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
}
DWORD WINAPI MyMouseLogger(LPVOID lpParm)
{
HINSTANCE hInstance = GetModuleHandle(NULL);
// here I put WH_MOUSE instead of WH_MOUSE_LL
/// hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, mouseProc, hInstance, NULL);
hMouseHook = SetWindowsHookEx( WH_MOUSE_LL, mouseProc, hInstance, NULL );
MSG message;
while (GetMessage(&message, NULL, 0, 0)) {
TranslateMessage(&message);
DispatchMessage(&message);
}
UnhookWindowsHookEx(hMouseHook);
return 0;
}
int main(int argc, char** argv)
{
HANDLE hThread;
DWORD dwThread;
hThread = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)MyMouseLogger, (LPVOID)argv[0], NULL, &dwThread);
if (hThread)
return WaitForSingleObject(hThread, INFINITE);
else
return 1;
}