控制鼠标移动

vs2013 wn32 cmd程序。
从别的网站拷贝的,稍微改了下。

#include 
#include 
#include 

void MouseMove(const int x, const int y)
{
	const double fScreenWidth = ::GetSystemMetrics(SM_CXSCREEN) - 1;
	const double fScreenHeight = ::GetSystemMetrics(SM_CYSCREEN) - 1;
	const double fx = x * (65535.0f / fScreenWidth);
	const double fy = y * (65535.0f / fScreenHeight);
	mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, (DWORD)fx, (DWORD)fy, 0, 0);
}

int main()
{
	srand((unsigned int)time(0));
	while (true)
	{
		POINT point_temp;
		::GetCursorPos(&point_temp);
		int iDisXY = rand() % 3;
		while (iDisXY == 0){ iDisXY = rand() % 3; }
		printf("move mouse to %d, %d\n", point_temp.x + iDisXY, point_temp.y + iDisXY);
		MouseMove(point_temp.x + iDisXY, point_temp.y + iDisXY);
		Sleep(1000 * 60);
	}
	return 0;
}

你可能感兴趣的:(cpp,c++)