目的
使用Windows API,控制鼠标在屏幕上随机移动。
重点
BOOL SetCursorPos(int X, int Y),将光标移动到屏幕上的指定位置。头文件:winuser.h;库文件:user32.lib
void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo),模拟鼠标事件。
详细参数说明可参阅:https://msdn.microsoft.com/zh-cn/windows/ms646260(v=vs.100)
代码示例
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <time.h>
#define MAX_RANGE (1000)
#define random(x) (rand()%x)
int _tmain(int argc, _TCHAR* argv[])
{
int nStep = 10;
int nK = 2;
int nX = 100;
int nY = 100;
int nTimeStep = 10000;
while (1)
{
//nX = nK * nX + nStep;
//nY = nK * nY + nStep;
srand((int)time(0));
nX = nK * random(MAX_RANGE) + nStep;
nY = random(M