import java.awt.*; import java.util.*; public class Hal{ public static void main(String[] args) throws Exception{ Robot hal = new Robot(); Random random = new Random(); while(true){ hal.delay(1000 * 60); int x = random.nextInt() % 640; int y = random.nextInt() % 480; hal.mouseMove(x,y); } } }
import java.awt.Robot; import java.awt.event.KeyEvent; public class Notepad { static int keyInput[] = { KeyEvent.VK_J, KeyEvent.VK_A, KeyEvent.VK_V, KeyEvent.VK_A, KeyEvent.VK_SPACE }; public static void main(String[] args) throws Exception { Runtime.getRuntime().exec("notepad"); Robot robot = new Robot(); for (int i = 0; i < keyInput.length; i++) { robot.keyPress(keyInput[i]); robot.delay(100); } } }
public void focusBelow() { if (SX.isMac()) { // TODO: replace this hack with a more robust method // Mac's hack to bring focus to the window directly underneath // this hack works on the assumption that the caller has // the input focus but no interaction area at the current // mouse cursor position // This hack does not work well with applications that // can receive mouse clicks without having the input focus // (e.g., finder, system preferences) // robot.mousePress(InputEvent.BUTTON1_MASK); // robot.mouseRelease(InputEvent.BUTTON1_MASK); // Another temporary hack to switch to the previous window on Mac robot.keyPress(KeyEvent.VK_META); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_META); robot.keyRelease(KeyEvent.VK_TAB); // wait a little bit for the switch to complete robot.delay(1000); } }
@Override public void playback(java.awt.Robot awtRobot, double playbackSpeed) { awtRobot.delay((int) (delayInSeconds / playbackSpeed * 1000)); }
/** * Delays for the press/release. */ private void delayForPressRelease() { if (this.isRequirePressReleaseDelay) { this.robot.delay(MIN_PRESS_RELEASE_DELAY); } }
public void typeKeys(final String text) { if (text != null) { for (int i = 0; i < text.length(); i++) { typeKey(text.charAt(i)); robot.delay(50); } } }
Robot r = new Robot(); doLeftMouseClick(r, 272, 241); r.delay(1000); doLeftMouseClick(r, 272, 241); r.keyPress(KeyEvent.SHIFT_MASK);
public static void main(String[] args) throws IOException, AWTException { // Move it to here: Key keyObject = new Key(); JFrame.addKeyListener(keyObject); final Robot robot = new Robot(); robot.delay(2000); while(keyObject.spacebarPressed()) { ....
// Start Robot in a new thread. new Thread(new Runnable() { @Override public void run() { Robot robot = new Robot(); robot.delay(1000); robot.keyPress(KeyEvent.VK_ESCAPE); } }).start(); // Launch JFileChooser. jFileChooser.getSelectedFile();
public class MoveMouse { Robot ro; public MoveMouse(int x, int y) throws AWTException{ ro = new Robot(); ro.mouseMove(x, y); ro.delay(1000); // 1 second delay } }
try { Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); robot.delay(200); }
public static void delay(ActionContext actionContext){ Thing self = (Thing) actionContext.get("self"); java.awt.Robot robot = (java.awt.Robot) self.doAction("getRobot", actionContext); int ms = self.getInt("ms"); robot.delay(ms); }
Runtime.getRuntime().exec("notepad"); Robot r = new Robot(); r.setAutoDelay(100); r.delay(500); r.keyPress(KeyEvent.VK_H); r.keyPress(KeyEvent.VK_E); r.keyPress(KeyEvent.VK_L); r.keyPress(KeyEvent.VK_L); r.keyPress(KeyEvent.VK_O);
Robot r = new Robot(); r.keyPress(KeyEvent.VK_ALT); r.keyPress(KeyEvent.VK_TAB); r.delay(10); //set the delay r.keyRelease(KeyEvent.VK_ALT); r.keyRelease(KeyEvent.VK_TAB);