Ghnb Trcv
Ghnb Trcv

Reputation: 59

Simple AutoClicker clicks only once instead of number of times

Ok, so I try the code a simple autoclicker. I have a button, I want to click on it, then wait a bit, maybe 500ms and then the program should click 10 times on the current cursor location with 300ms delay between each click

for some reason it does the click just once and not 10 times like I wanted

private void Button3_Click(object sender, EventArgs e) {

        System.Threading.Thread.Sleep(500);
        for (int i = 0; i < 10; i++)
        {
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
            System.Threading.Thread.Sleep(300);

            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
        }

Upvotes: 0

Views: 882

Answers (2)

M W
M W

Reputation: 86

Put a small delay between mouse down and mouse up. Also your code, if working properly, would click twice per loop. So 20 times.

    System.Threading.Thread.Sleep(500);
    for (int i = 0; i < 10; i++)
    {
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
        System.Threading.Thread.Sleep(50);
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

        System.Threading.Thread.Sleep(250);
    }

Upvotes: 2

    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

    System.Threading.Thread.Sleep(300);

    for (int i = 0; i < 10; i++)
    {
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    }

Upvotes: 0

Related Questions