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

· · 个人记录

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

源代码:

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

搭配随机数生成:

#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} 警告:慎用,一经运行只能关机

#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")更好食用