I’ve created an autoclicker and I expected there to be clicks while the mouse button is held down, but it’s only sending one click when the mouse button is held down. Can somebody enlighten me?
#include <iostream>
#include <Windows.h>
int main() {
bool mouseDown = false;
while (!GetAsyncKeyState(VK_ESCAPE)) {
Sleep(100);
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
if (!mouseDown) {
INPUT input = { 0 };
input.type = INPUT_MOUSE;
input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1, &input, sizeof(INPUT));
mouseDown = true;
}
}
else {
if (mouseDown) {
INPUT input = { 0 };
input.type = INPUT_MOUSE;
input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1, &input, sizeof(INPUT));
mouseDown = false;
}
}
}
return 0;
}
New contributor
WalkingPlough is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.