跳到正文

个人记录

C++控制台鼠标指定更改位置、随机更改位置及夺取鼠标控制权模版

DECEMBER12约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟

版本

  1. v1当前

需要头文件:#include<windows.h>

源代码:

C++
SetCursorPos(/*指定x坐标*/,/*指定y坐标*/);

搭配随机数生成:

C++
#include <windows.h>
#include <bits/stdc++.h>
using namespace std ;
int main()
{
	srand(time(0)) ;
	int x = GetSystemMetrics(SM_CXSCREEN) ;
	int y = GetSystemMetrics(SM_CYSCREEN) ;
	SetCursorPos(rand()%x,rand()%y) ; // 不论1次、100次还是1000次都是一闪而过
	return 0 ;
}

夺取鼠标控制权

警告:慎用,一经运行只能关机\color{red} 警告:慎用,一经运行只能关机

C++
#include <windows.h>
#include <bits/stdc++.h>
using namespace std ;
int main()
{
	srand(time(0)) ;
	int x=GetSystemMetrics(SM_CXSCREEN) ;
	int y=GetSystemMetrics(SM_CYSCREEN) ;
	while (1)
    {
		SetCursorPos(rand()%x,rand()%y) ;
	}
	return 0;
}

让您尽情享受鼠标乱飞的快感,搭配system(“shutdown -s -t 1”)更好食用

原文