cleverhans库——FGSM代码实战

Java基础差缺补漏系列之集合系列2

  返回  

VC模拟鼠标动作

2021/8/20 15:26:06 浏览:
// 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);



}

联系我们

如果您对我们的服务有兴趣,请及时和我们联系!

服务热线:18288888888
座机:18288888888
传真:
邮箱:888888@qq.com
地址:郑州市文化路红专路93号