[Tutorial] Mouse Macro Maker using jnativehook

Clicking can be a mundane task. Especially when you have to do it repeatedly without much thinking. I’m sure a lot of you have felt this. Many applications exist which offer mouse macro capabilities, but what’s the fun in that ?
Lets make our own program which will simplify clicking chores.

Naturally, jnativehook and java.awt.Robot are all we need. Java’s Robot class can effectively move and click your mouse without human intervention and jnativehook allows you to listen to system wide mouse and keyboard calls.

Graphical User Interface :
A simplistic GUI built using Eclipse’s Window Builder plugin should serve us well.

A button to start/stop recording the macro, one to load and one to save the macro are all we need. An integer spinner to set the delay between playback clicks is an added functionality.

Structure of the Application :
To keep the end code as simple as possible we only use two Java classes here. A Recorder class will be our main class. It implements jnativehook to record mouse clicks and save it in an easily readable text format. A Player class will read the saved macro and execute it using Java’s Robot Class.

 

The project can be found at https://github.com/Vetox/MouseMacroMaker

Karthi

Karthikeyan M : Geek, Gamer, Coder, Blogger - he shares his love of Technology in the form of tutorials, reviews, and how-to’s. An avid reader, he is a student at SRM university pursuing his B.Tech. in Information Technology.

Leave a Reply