Jones Jones - 1 month ago 19
C# Question

C# Autoclicker Visual Studio

I've made an autoclicker with C# using Visual Studio for personal learning purposes.

It works somehow but there's one frustrating problem explained below that I cannot solve no matter what I do. I've made various edits to the code and it should run on it's own thread now as well. As a last resort I went through other open source autoclickers and checked for tips from their codes but nothing has worked.

Here's a quick video clip. (When I turn on the autoclicker and hover over any dropdown menu it starts doing this). Interval doesn't matter and it clicks normally on everything else these dropdown menu's cause the problem.

https://gfycat.com/ContentGreedyFoal

Here's the whole Visual Studio project for those who would be kind enough to take a look:
https://drive.google.com/file/d/0B36Lvz9TiOAWNF80cVVXWnRjeHM/view?usp=sharing

And here's the code as well for those who don't have time to download the whole project. I apologize for lack of comments and confusing variable names. This is one of my first projects in C# and I would like to finish it to expand my knowledge.

http://pastebin.com/M1SiL9Rh

Thanks in advance.

Answer

I just had a brief look into your code, you seem to have a lot of loops here, that explains the clicking once you click the Start button.

private void MouseClicker()
    {
        int i = 0;
        while (true)
        {
            Thread.Sleep(100);
            while (threadStatus)
            {
                if (repeatTimes)
                {
                    while (startbutton.Enabled == false)
                    {
                        int x = Cursor.Position.X;
                        int y = Cursor.Position.Y;
                        mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x, y, 0, 0);
                    }
                }
                else if (randomInterval)
                {
                    while (startbutton.Enabled == false)
                    {
                        int li = Convert.ToInt32(Math.Round(lowerintervalvalue.Value, 0));
                        int hi = Convert.ToInt32(Math.Round(higherintervalvalue.Value, 0));
                        int x = Cursor.Position.X;
                        int y = Cursor.Position.Y;
                        mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x, y, 0, 0);
                        Random rand = new Random();
                        Thread.Sleep(rand.Next(li, hi));
                    }
                }
            }
        }
    }

You need logic inside this method to not click more than the Repeat times set in the window.

Comments