Mouse Automation in Java. Build your own GUI tool to record mouse actions and play them later.

This is a tutorial on how you can automate your mouse through Java. I have also created a small tool where you can save mouse inputs with arguments. After, you're done with feeding the inputs, click execute and the tool will execute all the inputs you have saved. This is a very useful tool if you want to automate a specific task. A checkbox allows you to repeat the execution infinite number of times. 







Here's a snippet of the code:


 Robot bot = null;
 try {

 bot = new Robot();
 bot.mouseMove(parameter, parameter2);

 int mask = InputEvent.BUTTON1_DOWN_MASK; //For Mouse Button1 Click
              bot.mousePress(mask); //Press Button
              bot.mouseRelease(mask); //Release Button


 } catch (Exception failed) {
   System.err.println("Failed instantiating Robot: " + failed);
  }
                






You can download the Java Executable if you want to run the program on your system from this link.

How to Execute:
1) Click on this link and download.
2) Open Terminal (CMD, if you're on windows).
3) Type cd /path/to/file
4) java -jar ./EmulateMouse.jar  (Make Sure you have java installed.)

How to use:

You have four options:

1) Move Mouse - This accepts two arguments. Enter the X and Y coordinates where you want your mouse to be moved.

2) Click - Emulates a mouse click.

3) Right Click - Emualtes a Right Click

4) Delay - Wait for x seconds.

Select the required option, enter correct arguments and click on Add Task.
Once you're done with adding tasks, click on Execute button. You can also check "Repeat" checkbox if you want these to be repeated. Please use Repeat very carefully. You might get stuck because your mouse will move automatically. (In such a case, you can go to your cmd where the EmulateMouse.jar process is running and press Ctrl+C to terminate the process)
 
 

You can find the GUI Tool and its source code at my GitHub Repo: https://github.com/SiddhantMinocha/EmulateMouse


The code is very easy and self explanatory. Hence, no need for long theories. ;)

Lots of Love! :)

SHARE ON:

Hi! I'm Siddhant Minocha, a Jaipur based hacker/developer. I spend most of my day coding things, trying to develop the next billion dollar idea. When I'm not over-analyzing random stuff and people, I hang out with friends (mostly entrepreneurs). I'm in my final year of graduation and till now I have started and exited 3 startups and developed a lot of websites and software for different companies. Follow me on twitter and other social networks to see what I keep doing. You can also hire me to design/develop your website, if you're worried about your website or app's security or any other tech related work. See ya! :D

    Blogger Comment

0 comments:

Post a Comment