#include <iostream>
#include <cstdlib>
#include <ctime>
#include <windows.h>
using namespace std;
int c;
void menu() {
cout << "Enter CPS: ";
cin >> c;
cout << "Autoclicker will activate when left mouse button is held down." << endl;
}
void mod() {
bool autoclickerActive = false;
while (true) {
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
if (!autoclickerActive) {
cout << "Autoclicker activated!" << endl;
autoclickerActive = true;
}
int lower = c - 6, upper = c + 10;
int random = lower + rand() % (upper - lower + 1);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(1000 / random);
} else {
if (autoclickerActive) {
cout << "Autoclicker deactivated." << endl;
autoclickerActive = false;
}
}
Sleep(10);
}
}
int main() {
srand(time(0));
menu();
mod();
return 0;
}
I'm trying to make it so that the autoclicker continuously clicks the left mouse button while the left mouse button is held down. The issue I'm facing is that the loop cancels itself after the 1st iteration because it sends leftup. So this program instantly stops when i press the left mouse button and hold it down. If I make it so that the autoclicker activates when i hold down the right mouse button, it works completely fine.
Is there a way to make the auto clicker click the left mouse button repeatedly while the user is holding down the left mouse button?
SendInput
instead of the oldmouse_event
API - Secondly: it may be easier to get it working correctly if you use a different trigger for it, using an unused button to do the repeated clicks.SendInput
) by sending key-up + key-down (in oneSendInput
message) instead of the other way around. example