Fantasy E-books by PhenomenalPen

Auto Clicker CSharp Tutorial – Let’s Learn Programming

Introduction – Simple Auto Clicker CSharp Tutorial

Want to create your own auto clicker this CSharp tutorial might help you. Basically auto clicker are software designed to do a certain job. To automatically click. Because sometimes its kinda feel dull doing recurring tasks. Basically we might want to have an app that can do this simple tasks for us. e.g:

  • Like surfing sites in traffic exchange websites,
  • boosting character experience in games,
  • or just simply making your clash of clans village online. To avoid being attacked. (In case your using your emulator to play such game).

I’m designing this auto clicker to achieve easiness in these certain tasks. But if you need to do much complicated jobs. Basically you might need to adjust the software to fulfill your needs. Additionally we can make more out of this simple auto clicker on our next CSharp tutorial.

Creating Auto Clicker in CSharp using Microsoft Visual Studio

  • Create a new project in Visual Studio
  • Select Visual C# Windows Form Application in the New Project form
  • And design your form exactly what the image shows
Auto Clicker CSharp Tutorial

Designing the software as simple as possible and focus on the most important function of the application.

  • option to set time interval
  • a simple label that shows the current status of the application
  • a start button that checks for a valid time interval and triggers the mouse click event
  • and a stop button that resets the form and stops the timer

Windows Form Auto Clicker Code


using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace ProEsc_AutoClicker {
      public partial class Main : Form {
      // declare a function residing in the user32.dll, this is the function needed to control mouse event
      [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
      public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);

      // declare variables and initialize its value
      private const int MOUSEEVENTF_LEFTDOWN = 0x02;
      private const int MOUSEEVENTF_LEFTUP = 0x04;
      private int X = Cursor.Position.X;
      private int Y = Cursor.Position.Y;

      // initialize a new instance of the timer class
      Timer timer = new Timer();

      // this loads the form and its control
      public Main() {
           InitializeComponent();
      }

      // the event that is triggered everytime the user starts the timer, this calls the mouse_event function with the parameters needed to locate mouse cursors and its button current state
      private void StartClicking(Object obj, EventArgs args) {
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, (uint)X, (uint)Y, 0, 0);
      }

      // this class returns an integer that will be declared as the timer interval value, the radio button in the form gives the user an option to select 5, 15, 20 to 60 seconds interval
      private int ClickInterval() {
            if (fifteenSecondsRadioButton.Checked == true) {
                  return 15000;
            } else if (twentySecondsRadioButton.Checked == true) {
                  return 20000;
            } else if (oneMinuteRadioButton.Checked == true) {
                  return 60000;
            } else {
                  // the default value of 5000 milliseconds / 5 seconds is returned every time a condition isn't met
                  return 5000;
            }
      }

      // buttons
      private void startClickingButton_Click(object sender, EventArgs e) {
            int interval = ClickInterval();
            stopButton.Enabled = true;

            // disable the group box that's holds the interval option so that the user cannot change it at runtime
            timerGroupBox.Enabled = false;

            // calls the event, assign the interval value and start the timer
            timer.Tick += new EventHandler(StartClicking);
            timer.Interval = interval;
            timer.Start();

            // the label value is changed to "clicking" to let the user knows the application current status
            status.Text = String.Format("Clicking with {0} seconds interval", interval / 1000);
            startClickingButton.Enabled = false;
      }

      private void stopButton_Click(object sender, EventArgs e) {
            // as soon as the stop button is clicked, enable start button and the timer interval group box
            startClickingButton.Enabled = true;
            timerGroupBox.Enabled = true;
            timer.Stop();

            // change the current status to "not clicking"
            status.Text = String.Format("Not clicking");
            stopButton.Enabled = false;
      }
}
}

Download Auto Clicker Installer

Additional Information

Be sure to add controls with the same name as what is declared in the code. Otherwise you’ll need to change the code to avoid errors. You can try adding masked text box to allow user to input his/her desired time interval. But be careful not to let the user set a value lower than 1 second. Because you might have a problem stopping your application from clicking.

The program needed .Net framework. Basically you need to install the framework if you want to use the software.

Happy coding.

Leave a Reply

Your email address will not be published. Required fields are marked *

11 + 18 =