C++模拟鼠标移动

下面是C++模拟鼠标移动的函数:

void MouseMove(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);
INPUT Input = { 0 };
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
Input.mi.dx = fx;
Input.mi.dy = fy;
::SendInput(1, &Input, sizeof(INPUT));
}

VS2013编译的控制台程序不能在XP运行的解决方案:

DEBUG->项目属性。

   General->Platform Toolset配置为: Visual Studio 2013 - Windows XP (v120_xp)

   Linker->System->SubSystem:配置为:Console (/SUBSYSTEM:CONSOLE)

posted on 2014-10-14 19:51  萧轩若怀  阅读(2890)  评论(0编辑  收藏  举报

导航