December 5, 2016

Creating an AutoClicker (That isn’t complete garbage).

I’ve seen quite a few posts on here regarding Autoclickers. Most new users or ones with little programming knowledge seem to be under the impression that an Autoclicker is some advanced piece of technology. Well, it’s not and I’ll show you how to make your very own right here. I hope that this will be explained in such a way that the target audience (underlined) will be able to follow.

First off, this isn’t going to be making something godly, this will just be the basics. I will point out areas that can be expanded upon but I will not be discussing those things in depth.

Lastly, I won’t be re-inventing the wheel. If there’s a good library to use or article that explains a topic I will link them respectively. If you have a question that is answered in a linked article I will not help you. If you have a question that isn’t answered then I’ll gladly respond.

Here’s the TL:DR for people who just want a gist of what to do:

  1. Science behind clicking
  2. Create thread
  3. Setup clicking mechanism
  4. Setup normal-distribution delay
  5. Extra neat but unnecessary additions

Step 0: Human performance

How do you click? What about the average Joe? I recorded myself and recorded everything in milliseconds. You can record your clicks per second here, but you won’t be able to calculate your standard deviation.

  • My average click is 155 milliseconds (6.5 ish clicks per second)
  • My minimum / maximum delays were 110 and 387 milliseconds.
  • My standard deviation of such a clicking spree is roughly 36.

What does this data look like on a graph? (Click to View)

Now that we know a little about a little about our natural clicking speed and its distribution on a graph we have an objective goal. Now we need to just reproduce results similar to this programatically.

Step 1: Setting up your workspace

Once we create a project we need to import any libraries we plan on using. For this project I’ll be using Apache Math. Java Native Access, and the Attatch API. Apache Math will be used for automatically calculating average, min/max, and standard deviation. JNA will be used for recording and sending mouse data. The Attatch API will be for hiding our Autoclicker process. I also have a few others but they’re for extra features that I’ll talk about at the end of the post. You do not need JNA if you do not wish to record yourself for your own statistics. You can just make them up with an educated guess.

Here’s how to import a library in the most popular IDEs:

  • Importing with IntelliJ
  • Importing with Eclipse
  • Importing with Netbeans

Here are the libraries I’ve imported (Click to View)

Step 2: Creating the main thread

The goal here is to have a looping block of code that clicks at a controlled random delay and doesn’t stop until we close the program. Technically it doesn’t have to be a thread, but due to how I’ve set up mine, I’ve made it a thread. In java a thread implementation looks like this:

PHP Code:
public class ExampleThread extends Thread {
public void run() {
// code here

PHP Code:
// Running our thread
ExampleThread t = new ExampleThread();

In the segment where I put “//code here” we’re going to create a while loop that will never stop. Then inside this loop I’ll put a call to a method that clicks my mouse, then a bit of code to generate a delay. It should look something like this when completed:

PHP Code:
while (true) {
// Clicking the mouse
// Calculating the next delay
double deviation stats.getStandardDeviation();
double mean stats.getMean();
int min =     stats.getMin();
int max =     stats.getMax();
// Create a value from -deviation to +deviation which tends to sit around 0
double randGauss = (random.nextGaussian() * deviation);
// Add the random gaussian value to the mean and clamp it to our min/max delays
long delayPreClamp Math.round(randGauss mean);
long delay = (longMathUtil.clamp(delayPreClampminmax);
    try {
// This has a try catch because the method "sleep" can throw
        // the exception InterruptedException. It probably won't but
        // java will force you to handle it just in case.
    } catch (
InterruptedException e) {

What I’ve not provided here is the method “Mouse.sendLeftClick()” and the variable stats. Now there are plenty of different ways to click the mouse. But this is the most simple to use. As for the stats, it is part of the Apache Math library that I mentioned above. What I do is record my keystrokes using JNA and record the delay between each click. If you do not wish to use JNA (It’s not for beginners) you can instead set the variables to pre-defined numbers.

Step 3: Creating a user-interface (Optional)

I say this is optional because at this point you can control the program through a console window. Technically once step 2 is complete you’ve made an Autoclicker that isn’t total garbage. It’s based on a realistic normal distribution and with certain values can be identical to what a normal human’s clicking patterns are. From here on out the steps are optional.

The GUI is where all that I can say are just subjective opinions. There are hundreds of ways to create a user interface. I’ll list some options and you can explore them yourselves. In general all you want is something to turn the clicker off and on again. In order to do that you’ll need to change the thread pseudo-code so that just before the mouse click is called there is a check to see if it should click in the first place. For example you can just check if a checkbox is selected.

  • A top-most program with a single checkbox or button which toggles the clicker.
  • A program that isn’t top-most but instead listens for keystrokes to toggle the clicker.
  • A minecraft mod that used KeyInputEvents to toggle the clicker.

Additional reasons to creating a user-interface is that settings will be easily accessible and won’t have to be updated in the source every time you wish to change something. Sliders are excellent for this.

Step 4: Recording yourself for statistics (Optional)

The best way to get some good numbers for an autoclicker is to determine your own values based off of what you can do naturally. If you wish to go a little faster you can use your own values as a base and apply minor tweaks. For this I used JNA. However at the time of writing unlike the keyboard listener, there is no mouse listener. You have to make one yourself. A quick google search should provide you with all the information you need.

With a mouse hook created all I did was the following (Not exact code, but ideally the same):

PHP Code:
public void onMousePress() {
long currentSystem.currentTimeMillis();
        if (
lastClick != -1) { 
// stats = Apache Math DescriptiveStatistics
stats.addValue(currentlastClick );
lastClick current;

Each time I click the mouse (Even outside of the java window since it’s a native mouse listener) the delay between clicks is calculated. I wrapped my mouse hook in a thread which allows me to toggle it at will. If you do not wish to have a mouse hook active all the time you can create a new java project, record your stats there and copy them over.

To retrieve the information from the “stats” refer to the code I posted in the thread example. The methods are the same.

Step 5: Process merging with java agents (Optional)

Now we know how easy it is for somebody to open task manager and notice that there are two java processes running (Minecraft and the autoclicker). How can we hide our auto-clicker? Java agents!

The best thing about how simple Autoclickers are is that our java agent can be stupidly simple and do exactly what we want. The java agent will allow us to attach our Autoclicker as a java agent to a running JVM process, effectively hiding our Autoclicker in Minecraft’s (or any other java application’s) process. The complex operations such as class rewriting that java agents also introduce can be completely ignored since we don’t need that.

Let’s begin with creating an agent class.

PHP Code:
public class Agent {
    public static 
void agentmain(String argsInstrumentation inst) {

    public static void premain(String argsInstrumentation inst) {

    public static void agentmain(String args) {

    public static void premain(String args) {
// calls main method of our autoclicker program
MyAutoClicker.main(new String[] {});

The different method names and their arguments are added so that we can attach our agents in a variety of contexts. We can direct them all to a single method and have our program launched from there. We aren’t done just by slapping this agent class in our program. Our java agent will only work if it’s compiled to a java archive. In this archive we need to modify the manifest file to declare our agent class.

Here’s an example MANIFEST.MF file:

PHP Code:
Class-Path: .
Main-Class: me.autoclicker.MainClass
-Class: me.autoclicker.AgentClass 

Then we need to attatch it to the JVM. What I’ve done is made a alternate main method for calling attach methods.

PHP Code:
for (VirtualMachineDescriptor vm VirtualMachine.list()) {
// the display name starts with the launch args. 
    // Since the launch args always reference the main class, it's the easiest thing to find automatically
if (vm.displayName().contains("net.minecraft")) {
        try {
VirtualMachine vm VirtualMachine.attach(vmID);
// Options is what becomes the "args" in the agentmain/premain method. It can be an empty string, null, or anything you wish.
        } catch (
Exception e) {
            throw new 

Since we don’t need to edit anything in minecraft all you have to do is call the main method of your program where I put “// code here”.

Reminder: This code will be called from Minecraft’s JVM, so if you have and file IO in your program you’ll need to account for that. You can either use absolute paths in your clicker OR you can send in the data through the agent’s args. It’s only a single string so you’ll probably need to make use of String.split.

That’s everything I’ve could find that would separate an Autoclicker from the rest. If you have any suggestions or questions (That aren’t explained in anything I’ve linked) please do post them.

Category : Uncategorized

Leave a Reply

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

Proudly powered by Bolkya Resha and Software Testing Theme