Reputation: 59
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
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
Reputation: 11
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