Auto Clicker

how can i make that when left click is held it sent infinite left click, and when its no longer held it stop the infinite loop.

i tried:
1
2
3
4
5
while (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    Sleep(30);
    mouse_event(MOUSEEVENTF_LEFTUP,  0, 0, 0, 0);
}



not really works, cause the MOUSEEVENTF_LEFTUP it stop the held, but if i set MOUSEEVENT_LEFTDOWN after MOUSEEVENT_LEFTUP it'll infite loop but can't be stoped.
Last edited on
The help says use sendinput instead of mouse_event now. That is not critical, just FYI.

I think (not 100% sure) that what you need is:

1
2
3
4
5
6
7
8
9
10
while (GetAsyncKeyState(VK_LBUTTON) & 0x8000) 
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Sleep(30);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(30);

if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) 
  mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
}


assuming that I understood this and that the getasync gets the current 'real' device value and the events are 'soft' ?
Last edited on
i don't think that work @jonnin, well i tried use sendinput it just like mouse_event, send output infinite left click.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <windows.h>

void LeftClick ( )
{  
  INPUT    Input={0};
  // left up
  Input.type      = INPUT_MOUSE;
  Input.mi.dwFlags  = MOUSEEVENTF_LEFTUP;
  ::SendInput(1,&Input,sizeof(INPUT));

  // left down 
  ::ZeroMemory(&Input,sizeof(INPUT));
  Input.type      = INPUT_MOUSE;
  Input.mi.dwFlags  = MOUSEEVENTF_LEFTDOWN;
  ::SendInput(1,&Input,sizeof(INPUT));
}

int main()
{
    while (GetAsyncKeyState(VK_LBUTTON) & 0x8000){
        LeftClick();
    }
}
I think you still need an extra condition.
I think you need

while (hardware is down) //loop
{ //your function body
left up event
left down event

if hardware is up
left up event again //this should help stop the while loop, if I understand the issue
}

so that if the hardware is up, it sends the up event as the last thing seen, which should stop the while loop. If that does not work, you can also try putting an 'if hardware up, send up and return' at the top of the function.

Topic archived. No new replies allowed.