win32模拟鼠标动作

#include
#include
#include 
#include 

using namespace std;

void thMoveMouse()
{
    POINT p;
    while (1) {
        GetCursorPos(&p);//获取鼠标坐标 
        std::cout << p.x << " " << p.y << std::endl;
        SetCursorPos(1350, 16);//更改鼠标坐标
        //SetPhysicalCursorPos(p.x - 300, p.y - 300);
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);//按下左键
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);//松开左键
        Sleep(1000);
        GetCursorPos(&p);//获取鼠标坐标 
        std::cout << p.x << " " << p.y << std::endl;
        SetCursorPos(615, 879);//更改鼠标坐标 
        //SetPhysicalCursorPos(p.x + 300, p.y + 300);
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);//按下左键
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);//松开左键
        Sleep(1000);//控制移动时间间隔 
    }
}

int main()
{
    thread thLeft(thMoveMouse);
    thLeft.join();

    return 0;
}

 

你可能感兴趣的:(小练习代码)