示例程序
#include <iostream> #include <windows.h> #include <ctime> using namespace std; int main(int argc, char **argv) { int x = GetSystemMetrics(SM_CXSCREEN); //鼠标x轴 int y = GetSystemMetrics(SM_CYSCREEN); //鼠标y轴 srand(time(0));//随机函数种子 int i = 0; while (i < 10) //循环 { i++; SetCursorPos(rand() % x, rand() % y); //鼠标 x y轴 随机 Sleep(1000); } return 0; }
获取鼠标位置
int x = GetSystemMetrics(SM_CXSCREEN); //鼠标x轴 int y = GetSystemMetrics(SM_CYSCREEN); //鼠标y轴
设置鼠标位置
SetCursorPos(rand() % x, rand() % y); //鼠标 x y轴 随机