有趣的代码
2026-10-30 20:32:06
发布于:浙江
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main() {
// 设置随机数种子
srand(time(0));
// 定义鼠标位置结构体
POINT mouse;
while (true) {
// 获取当前鼠标位置
GetCursorPos(&mouse);
// 随机生成新的鼠标位置
mouse.x = rand() % GetSystemMetrics(SM_CXSCREEN); // 屏幕宽度范围
mouse.y = rand() % GetSystemMetrics(SM_CYSCREEN); // 屏幕高度范围
// 输出新位置到控制台
cout << "Mouse Position: " << mouse.x << ", " << mouse.y << endl;
// 设置鼠标到新位置
SetCursorPos(mouse.x, mouse.y);
// 随机延迟一段时间(0-500毫秒)
Sleep(rand() % 500);
}
return 0;
}
全部评论 2
安全版:
#include <windows.h> #include <cstdlib> #include <ctime> #include <iostream> using namespace std; int main() { // 设置随机数种子 srand(time(0)); // 定义鼠标位置结构体 POINT mouse; // 当没有按下 ESC 键时,持续循环 while (!(GetAsyncKeyState(VK_ESCAPE) & 0x8000)) { // 获取当前鼠标位置 GetCursorPos(&mouse); // 随机生成新的鼠标位置 mouse.x = rand() % GetSystemMetrics(SM_CXSCREEN); // 屏幕宽度范围 mouse.y = rand() % GetSystemMetrics(SM_CYSCREEN); // 屏幕高度范围 // 输出新位置到控制台 cout << "Mouse Position: " << mouse.x << ", " << mouse.y << endl; // 设置鼠标到新位置 SetCursorPos(mouse.x, mouse.y); // 随机延迟一段时间(0-500毫秒) Sleep(rand() % 500); } cout << "程序已安全退出!" << endl; return 0; }2026-11-02 来自 广东
1谁敢运行
2026-11-02 来自 广东
0




















有帮助,赞一个