c++ - 如何使用 rand 随机化模拟点击
问题描述
我正在用 C++ 制作一个自动点击器它可以工作,但是,我正在尝试使用 rand 函数中的最小和最大整数来随机化它。
它随机化,但它从未真正超过 12 cps。我是 C++ 新手,我来自 C#。
这是我的所有代码:
#include <iostream>
#include<Windows.h>
#include<stdlib.h>
#include <random>
using namespace std;
int x = 0, y = 0, Mincps, Maxcps, randomized_cps;
bool click = false;
int randomize_cps(int min, int max);
void Menu()
{
system("color 5");
cout << "Minimum CPS: ";
cin >> Mincps;
system("CLS");
cout << "Maximum CPS: ";
cin >> Maxcps;
system("CLS");
if (Mincps > 20 || Maxcps > 20 || Mincps < 1 || Maxcps < 1)
{
cout << "That CPS is not safe" << endl;
Sleep(1000);
system("CLS");
Menu();
}
cout << "AirClicker\n";
cout << "Made by Deagan";
Sleep(1500);
system("CLS");
cout << "Minimum CPS: ";
cout << Mincps;
cout << "\n\n";
cout << "Maximum CPS: ";
cout << Maxcps;
cout << "\n\n";
cout << "Press X to toggle on and Z to toggle off.\n";
}
void Clicker()
{
while (1)
{
if (GetAsyncKeyState('X'))
{
click = true;
}
if (GetAsyncKeyState('Z'))
{
click = false;
}
if (click == true)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
Sleep(1000 / randomized_cps);
}
}
}
int main()
{
Menu();
Clicker();
}
int randomize_cps(int min, int max)
{
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distr(Mincps, Maxcps);
randomized_cps = distr(gen);
return 0;
}
任何帮助表示赞赏,谢谢!有人请帮助我使用随机发生器,它应该在几天内完成。
解决方案
这将根据您的需要休眠 1 到 20 之间的随机值:
#include <Windows.h>
#include <iostream>
#include <random>
int main()
{
std::default_random_engine generator;
std::uniform_int_distribution<int> distribution(1, 20);
while (1)
{
int random_value = distribution(generator);
std::cout << random_value << std::endl;
Sleep(random_value); // this is already in milliseconds
}
return 0;
}
推荐阅读
- angular - 如何避免使用ngModel
- mysql - 无法启动 MySQL 容器并将其附加到 Docker 网络
- sql - 根据表 1 的值,从多个表中找到两个重复值
- eclipse - 在 Zoom 中共享 Eclipse 窗口
- python - Pycharm venv 包对我不可用?
- c++ - 编写一个应该以 root 身份运行的 c++ linux 程序
- python - 来自共现矩阵的 Scipy 相关矩阵(用于通过社区检测进行主题建模)
- tensorflow - 在预训练网络中间添加 dropout
- c++ - 我收到此错误致命错误: Scintilla.h: No such file or directory when loading scintilla library
- flutter - 在按下按钮时动态添加一个小部件