jeudi 18 juin 2020

How to randomize simulated clicks using rand

i am making an autoclicker in c++ It works, but, i am trying to randomize it using a min and max integer in the rand function. i tried this

randomized_cps = rand() % ((Maxcps - Mincps) + 1) + Mincps;

But it only returns the max cps and doesn't randomize it.

Here is all my code:

#include <iostream>
#include<Windows.h>
#include<stdlib.h>
#include <time.h>
#include <random>
using namespace std;


int x = 0, y = 0, Mincps, Maxcps, randomized_cps;
string clickerStatus;
bool click = false;






void Menu()
{
    system("color 5");
    cout << "Minimum CPS: ";
    cin >> Mincps;
    system("CLS");

    cout << "Maximum CPS: ";
    cin >> Maxcps;
    system("CLS");

    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.";

    randomized_cps = rand() % ((Maxcps - Mincps) + 1) + Mincps;
}

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();
}

Any help is appreciated, thanks!




Aucun commentaire:

Enregistrer un commentaire