Description

Bot is an evil little program that lets you automate your mouse and keyboard. Applications can be to fill internet forms, copy excel cells or do other no-brain work without any effort.
For the correct setup I have also included the method position() which frequently reads out the cursors position.

Security Features

A program which moves your mouse all the time can be quite hard to stop. The most intuitive way would be a global keyboard listener that stops the Bot when hitting for example the Esc key. Unfortunately there is no way to use a global keyboard listener in pure java, it only works when a Java window is in focus.
So I found another way to quit the Bot: When the Bot is initialized, a Java window in fullscreen mode is launched iconified. When the bot is running and you press Alt+Tab, eventually this window will come into focus. As soon as it does, the Bot gets stopped.


Source Code

import java.awt.event.*; import java.awt.Robot; import java.awt.MouseInfo; import javax.swing.JFrame; import java.awt.Color; import javax.swing.event.MouseInputAdapter; import java.awt.datatransfer.DataFlavor; import java.awt.Toolkit; public class Bot extends JFrame { // ######################################################################################################### public static void horizons() { new Bot(); String name, data; float r, m; for(int i=11; i<15; i++) { moveMouse(376, 429); click(); pause(0.6); moveMouse(615, 582); click(); text(""+i); enter(); pause(0.7); moveMouse(660, 522); click(); pause(0.6); moveMouse(521, 130); clickDouble(); copy(); name = clipboard().replaceAll("\\s+",""); moveMouse(493, 341); clickDouble(); copy(); try { r = Float.parseFloat(clipboard().replaceAll("\\s+","")); } catch(Exception e) { r = 1E15f; } m = (float)(4.0/3.0*Math.PI*r*r*r * 2.71E12); scrollDown(16); moveMouse(621, 394); dragMouse(1635, 394); copy(); data = clipboard(); System.out.println("physX.insert(\"" + name + "\", Color.GRAY, " + r + "*r, " + m + ", " + data + ");"); scrollUp(16); } } public static void example() { new Bot(); for(int i=0; i<5; i++) { moveMouse(629, 396); clickMiddle(); pause(0.3); moveMouse(344, 141); click(); pause(0.8); } for(int i=0; i<20; i++) { moveMouse(629, 396); clickMiddle(); pause(0.3); moveMouse(344, 141); click(); pause(0.9); moveMouse(575, 13); click(); pause(0.1); } pause(0.3); moveMouse(575, 13); for(int i=0; i<5; i++) { click(); pause(0.3); } } // ######################################################################################################### private static Robot bot; private Bot() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setExtendedState(JFrame.MAXIMIZED_BOTH); setUndecorated(true); getContentPane().setBackground(Color.BLACK); setState(JFrame.ICONIFIED); setVisible(true); addMouseListener(new MouseInputAdapter() { public void mouseEntered(MouseEvent e) { System.exit(0); } }); try { bot = new Robot(); } catch(Exception e) {} bot.setAutoDelay(15); pause(3); } public static void position() { while(true) { int x = (int)MouseInfo.getPointerInfo().getLocation().getX(); int y = (int)MouseInfo.getPointerInfo().getLocation().getY(); System.out.println("moveMouse(" + x + ", " + y + ");"); pause(0.166); } } private static void moveMouse(int x, int y) { bot.mouseMove(x, y); } private static void dragMouse(int x, int y) { bot.mousePress(InputEvent.BUTTON1_MASK); bot.mouseMove(x, y); bot.mouseRelease(InputEvent.BUTTON1_MASK); } private static void click() { bot.mousePress(InputEvent.BUTTON1_MASK); bot.mouseRelease(InputEvent.BUTTON1_MASK); } private static void clickDouble() { bot.mousePress(InputEvent.BUTTON1_MASK); bot.mouseRelease(InputEvent.BUTTON1_MASK); bot.mousePress(InputEvent.BUTTON1_MASK); bot.mouseRelease(InputEvent.BUTTON1_MASK); } private static void clickRight() { bot.mousePress(InputEvent.BUTTON3_MASK); bot.mouseRelease(InputEvent.BUTTON3_MASK); } private static void clickMiddle() { bot.mousePress(InputEvent.BUTTON2_MASK); bot.mouseRelease(InputEvent.BUTTON2_MASK); } private static void scrollUp(int x) { for(int i=0; i<x; i++) { bot.mouseWheel(-1); pause(0.03); } } private static void scrollDown(int x) { for(int i=0; i<x; i++) { bot.mouseWheel(1); pause(0.03); } } private static void text(String s) { char[] c = s.toCharArray(); final int d = bot.getAutoDelay(); bot.setAutoDelay(0); for(int i=0; i<c.length; i++) { key(c[i]); } bot.setAutoDelay(d); } private static void key(char c) { // works for text and numbers if(c>=65 && c<=90) { bot.keyPress(16); // Shift bot.keyPress(c); // big letters bot.keyRelease(c); bot.keyRelease(16); // Shift } else if(c>=97 && c<=122) { bot.keyPress(c-32); // small letters bot.keyRelease(c-32); } else if(c==32 || c==46 || (c>=48 && c<=57)) { bot.keyPress(c); // space, point and numbers bot.keyRelease(c); } } private static void enter() { // enter key bot.keyPress(10); bot.keyRelease(10); } private static void copy() { bot.keyPress(17); // Ctrl bot.keyPress(67); bot.keyRelease(67); bot.keyRelease(17); // Ctrl } private static void cut() { bot.keyPress(17); // Ctrl bot.keyPress(88); bot.keyRelease(88); bot.keyRelease(17); // Ctrl } private static void paste() { bot.keyPress(17); // Ctrl bot.keyPress(86); bot.keyRelease(86); bot.keyRelease(17); // Ctrl } private static String clipboard() { // get copied text from clipboard String s = ""; try { s = (String)Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); } catch(Exception e) {} return s; } private static void pause(double s) { if(s > 0) { try { Thread.sleep((int)(s*1E3)); } catch(Exception e) {} } } }

Demo