用以下代码可实现C++模拟鼠标移动:
#include <iostream>
#include <Windows.h>
void Mouse_Move(int x, int y)
{
double fScreenWidth = ::GetSystemMetrics(SM_CXSCREEN) - 1;
double fScreenHeight = ::GetSystemMetrics(SM_CYSCREEN) - 1;
double fx = x * (65535.0f / fScreenWidth);
double fy = y * (65535.0f / fScreenHeight);
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, fx, fy, 0, 0);
}
int main()
{
POINT p;
::GetCursorPos(&p);
Mouse_Move(p.x+50, p.y+50);
return 0;
}