// mouse.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include <Windows.h>
#include <stdio.h>
#include <vector>
enum ENUM_ACTION
{
ACTION_MOVE =0,
ACTION_CLICK,
ACTION_SLEEP
};
typedef struct _ACTION_STRUCT
{
ENUM_ACTION action;
int x;
int y;
int sleep;
}ACTION_STRUCT,*PACTION_STRUCT;
void DoMove(int x, int y)
{
SetCursorPos(x, y);
}
void DoClick(int x, int y)
{
SetCursorPos(x, y);
Sleep(10);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Sleep(10);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
void DoSleep(int x)
{
Sleep(x);
}
int main(int arc,char* argv[])
{
if (arc > 1)
{
while (1)
{
POINT pt;
GetCursorPos(&pt);
printf("%d,%d\n", pt.x, pt.y);
Sleep(100);
}
}
std::vector<ACTION_STRUCT> arr;
char buff[512] = { 0 };
FILE* fp = fopen("script.txt", "rt");
int loop = 1;
while (fgets(buff, sizeof(buff), fp))
{
char* p = strstr(buff, "move ");
if (p != NULL)
{
p = p + strlen("move ");
int x = atoi(p);
p = strstr(p, ",");
int y = atoi(p + 1);
printf("move %d %d\n", x, y);
ACTION_STRUCT a;
a.action = ACTION_MOVE;
a.x = x;
a.y = y;
arr.push_back(a);
continue;
}
p = strstr(buff, "sleep ");
if (p != NULL)
{
p = p + strlen("sleep ");
int s = atoi(p);
printf("sleep %d\n", s);
ACTION_STRUCT a;
a.action =ACTION_SLEEP;
a.sleep = s;
arr.push_back(a);
continue;
}
p = strstr(buff, "click ");
if (p != NULL)
{
p = p + strlen("click ");
int x = atoi(p);
p = strstr(p, ",");
int y = atoi(p + 1);
printf("click %d %d\n", x, y);
ACTION_STRUCT a;
a.action = ACTION_CLICK;
a.x = x;
a.y = y;
arr.push_back(a);
continue;
}
p = strstr(buff, "loop ");
if (p != NULL)
{
p = p + strlen("loop ");
loop = atoi(p);
continue;
}
}
fclose(fp);
printf("loop=%d\n", loop);
int i = 0;
while(1)
{
for (int k = 0; k < arr.size(); k++)
{
if (arr[k].action == ACTION_MOVE)
{
DoMove(arr[k].x, arr[k].y);
}
else if (arr[k].action == ACTION_CLICK)
{
DoClick(arr[k].x, arr[k].y);
}
else if (arr[k].action == ACTION_SLEEP)
{
DoSleep(arr[k].sleep);
}
}
if (loop == 0)
{
continue;
}
else if(i++>loop)
{
break;
}
Sleep(5000);
}
printf("exit\n");
//Sleep(1000);
//POINT lpPoint;
//for (int i = 0; i < 10; i++)
//{
// lpPoint.x = 100+i*100;
// lpPoint.y = 100;
// SetCursorPos(lpPoint.x, lpPoint.y);
// printf("%d\n", i);
// Sleep(500);
//}
//mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
//mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
VC模拟鼠标动作
最新推荐文章于 2022-09-17 13:27:45 发布