#include <Windows.h>
#include <stdio.h>
using namespace std;
bool isMouseMove(long long x, long long y);
void LockScreen();
long long iMouseX = 0;
long long iMouseY = 0;
bool flag = false;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
typedef struct point {
LONG x;
LONG y;
};
void GetMouseLocation() {
POINT lpPoint;
if (GetCursorPos(&lpPoint) == 0) {
wchar_t* pszText = L"鼠标位置获取失败";
WriteConsole(hOut, pszText, wcslen(pszText), NULL, NULL);
}
long long x = lpPoint.x;
long long y = lpPoint.y;
if (!isMouseMove(x, y)) {
LockScreen();
exit(0);
}
return;
}
bool isMouseMove(long long x, long long y) {
if (flag) {
if (x != iMouseX || y != iMouseY) {
return false;
}
return true;
}
else {
flag = true;iMouseX = x;iMouseY = y;
return true;
}
}
void LockScreen() {
system("rundll32.exe user32.dll,LockWorkStation");
Sleep(100);
return;
}
int main() {
Sleep(7000);
printf("开始\n");
while (1) {
Sleep(100);
GetMouseLocation();
}
return 0;
}