Problem with click on loop

Hello, so i am beginning with c++ and i make an "autoclick" but when i leftclick the first click is going so fast like "0, 2, 3, 4, 5, ...."
My friend told me to do a flag to check if its the first click or not but i tried and its work the first time when i click but not when i click 2nd time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  while (running) {

    if (GetAsyncKeyState(VK_END)) running = false;

        if(GetAsyncKeyState(VK_LBUTTON) && test) {
            Sleep(75);

        }

        if(GetAsyncKeyState(VK_LBUTTON) && enabled) {
            test = false;
            int cps = (rand()%(max-min+1))+min;
            GetCursorPos(&pt);
            PostMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(pt.x, pt.y));
            PostMessage(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(pt.x, pt.y));
            Sleep(1000/cps);

        }
You don't need to double post:
http://www.cplusplus.com/forum/beginner/269815/
Topic archived. No new replies allowed.