← Back to Home
advertisement
Create a simple bot creator in 33 lines of code

Create a simple bot creator in 33 lines of code

Hi, I'm Amr Hesham and I'm a software engineer interested in Android development and compiler design, and I love playing some RPG games, but some of those games are designed to make your stay in the game as long as possible, so they give you some repetitive and boring tasks to do and maybe every day, for example, collecting various items... etc., so I've been looking for a bot builder to use and automate those tasks. I found a good one with many functions like controlling mouse, keyboard, screen, checking pixel color with some helper statements like if, loop…etc. But to create your script you need to add a list of commands with the GUI, which means you can write a script like any programming language and I hated this idea. So after trying this program I had a question: how can I design one like this or maybe better? I started searching how to control the mouse, screen and keyboard in Java and after doing some research I got a lot of answers and found an awesome class in Java called Robot. Robot as you can see in the Oracle documentation. "This class is used to generate native system input events for test automation, self-running demonstrations, and other applications where the control of..." and it has many useful methods to do exactly what I want, and in this time I read some Compiler Design books and created many toy programming languages, and I also have good experience in JavaFX Framework, so I found that it would be awesome if I merged my experience in Compiler Design, JavaFX and Robot Class to create my amazing Bot Creator Project. I started to create a scripting programming language with keywords for mouse, keyboard and screen, then I added support for statements, so I added if, while, repeat statements, after that, I want to make it easier for the user to create a complex bot, so I added support for variables, functions and built-ins, for example, I added a built-in function called pixelColor to get the pixel value of the current mouse position, after finishing this language, it's time for JavaFX to start, like this I have created a simple editor for it with some buttons like run, stop, restart...etc. and this is the result I called SnapMacro. After finishing this project and using it in online games, I also used it to write a bot for Linkedin to add people or maybe I can use it to accept inventions from many people and other things. This is the story behind SnapMacro, by the way, Snap is the name of my programming language, but the article does not end here and the goal is not only to tell my story but to show you how to create a simple bot builder in just 33 lines with the same concept. Yes, as you can see, it will only be 33 lines of code! We won't create a scripting language or support declarations or variables, but we will create a simple bot builder that supports mouse and keyboard commands. So first, what do we want from our little bot builder? Basically, we will support 3 types of commands and the result will be 7 commands. Mouse commands x y mouse movement press mouse right | left release the mouse to the right | left mouse wheel x Keyboard commands press keyboard x keyboard release x delay commands delay x So, let's start creating our bot builder and we will use the Kotlin programming language in this article, but you can also use Java or take the concept and use your favorite programming language, it doesn't matter. First, we will use the Scanner class to read user input from the console and initialize an instance of the Robot class and tell the user when to check what the current command type is. fun main() { scanner val = Scanner(System.`in`) robot value = Robot() while (scanner.hasNext()) { when (scanner.next()) { "mouse" -> {} "keyboard" -> {} "delay" -> {} } } } And now, within each type, we need to support some commands, so let's start with the small one.
advertisement

Related Articles

advertisement