Example usage for java.awt Robot mouseMove

List of usage examples for java.awt Robot mouseMove

Introduction

In this page you can find the example usage for java.awt Robot mouseMove.

Prototype

public synchronized void mouseMove(int x, int y) 

Source Link

Document

Moves mouse pointer to given screen coordinates.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Robot robot = new Robot();
    robot.mouseMove(500, 500);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Robot r = new Robot();
    r.mouseMove(35, 35);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    Thread.sleep(50);//from   w  w  w.j  a va 2 s .c  o  m
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    Robot r = new Robot();
    r.mouseMove(35, 35);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    Thread.sleep(50);//from ww w. j a  v  a2 s  . c  o m
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    robot.mouseMove(200, 200);

    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.mouseWheel(-100);/*  w w w .  j  a  va 2 s  .  co  m*/
}

From source file:RobotTest.java

/**
 * Runs a sample test procedure/*w  w  w . j  a  v  a 2  s .c  o  m*/
 * 
 * @param robot
 *          the robot attached to the screen device
 */
public static void runTest(Robot robot) {
    // simulate a space bar press
    robot.keyPress(' ');
    robot.keyRelease(' ');

    // simulate a tab key followed by a space
    robot.delay(2000);
    robot.keyPress(KeyEvent.VK_TAB);
    robot.keyRelease(KeyEvent.VK_TAB);
    robot.keyPress(' ');
    robot.keyRelease(' ');

    // simulate a mouse click over the rightmost button
    robot.delay(2000);
    robot.mouseMove(200, 50);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    // capture the screen and show the resulting image
    robot.delay(2000);
    BufferedImage image = robot.createScreenCapture(new Rectangle(0, 0, 400, 300));

    ImageFrame frame = new ImageFrame(image);
    frame.setVisible(true);
}

From source file:com.seleniumtests.driver.CustomEventFiringWebDriver.java

/**
 * move mouse taking screen placing into account. Sometimes, coordinates may be negative if first screen has an other screen on the left 
 * @param robot/*from ww w  .  ja  va2 s  .c o  m*/
 */
private static void moveMouse(Robot robot, int x, int y) {
    Rectangle screenRectangle = getScreensRectangle();
    robot.mouseMove(x + screenRectangle.x, y + screenRectangle.y);
}

From source file:com.o2d.pkayjava.editor.Main.java

private void toggleVisible() {
    mainFrame.setVisible(!mainFrame.isVisible());
    if (mainFrame.isVisible()) {
        mainFrame.toFront();/* w  w  w. j a v a 2s  . c  om*/
        mainFrame.requestFocus();
        mainFrame.setAlwaysOnTop(true);
        try {
            //remember the last location of mouse
            final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation();

            //simulate a mouse click on title bar of window
            Robot robot = new Robot();
            robot.mouseMove(mainFrame.getX() + 100, mainFrame.getY() + 5);
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

            //move mouse to old location
            robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY());
        } catch (Exception ex) {
            //just ignore exception, or you can handle it as you want
        } finally {
            mainFrame.setAlwaysOnTop(false);
        }
    }
}

From source file:org.cytoscape.ding.impl.cyannotator.dialogs.LoadImageDialog.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    try {//from  ww  w. j  a  va2  s. co m
        //Read the selected Image, create an Image Annotation, repaint the whole network and then dispose off this Frame
        File imageFile = jFileChooser1.getSelectedFile(); // Get the file
        BufferedImage image = ImageIO.read(imageFile);
        URL url = imageFile.toURI().toURL();
        //The Attributes are x, y, Image, componentNumber, scaleFactor
        ImageAnnotationImpl newOne = new ImageAnnotationImpl(cyAnnotator, view, (int) startingLocation.getX(),
                (int) startingLocation.getY(), url, image, view.getZoom(), cgm);

        newOne.addComponent(null);
        cyAnnotator.addAnnotation(newOne);
        newOne.getCanvas().repaint();

        // Set this shape to be resized
        cyAnnotator.resizeShape(newOne);

        try {
            // Warp the mouse to the starting location (if supported)
            Point start = newOne.getComponent().getLocationOnScreen();
            Robot robot = new Robot();
            robot.mouseMove((int) start.getX() + 100, (int) start.getY() + 100);
        } catch (Exception e) {
        }

        this.dispose();
    } catch (Exception ex) {
        logger.warn("Unable to load the selected image", ex);
    }
}

From source file:fxts.stations.trader.ui.ABaseDialog.java

public void componentShown(ComponentEvent aEvent) {
    try {//from  w w  w .ja v  a  2  s.c o  m
        UserPreferences preferences = UserPreferences.getUserPreferences(TradeDesk.getInst().getUserName());
        JButton button = getRootPane().getDefaultButton();
        if (preferences.getBoolean("Mouse.snapDefaultButton") && button != null) {
            // snap mouse to middle of default button
            Robot robot = new Robot();
            int x = (int) button.getLocationOnScreen().getX();
            int y = (int) button.getLocationOnScreen().getY();
            int width = (int) button.getSize().getWidth();
            int height = (int) button.getSize().getHeight();
            int x1 = x + width / 2;
            int y1 = y + height / 2;
            robot.mouseMove(x1, y1);
        }
    } catch (AWTException e) {
        e.printStackTrace();
    }
}

From source file:com.willwinder.universalgcodesender.model.GUIBackend.java

private void keepAwake() {
    logger.log(Level.INFO, "Moving the mouse location slightly to keep the computer awake.");
    try {//from  w  w w.  j  av  a  2  s  .  co m
        Robot hal = new Robot();
        Point pObj = MouseInfo.getPointerInfo().getLocation();
        hal.mouseMove(pObj.x + 1, pObj.y + 1);
        hal.mouseMove(pObj.x - 1, pObj.y - 1);
        pObj = MouseInfo.getPointerInfo().getLocation();
        logger.log(Level.INFO, pObj.toString() + "x>>" + pObj.x + "  y>>" + pObj.y);
    } catch (AWTException | NullPointerException ex) {
        Logger.getLogger(GUIBackend.class.getName()).log(Level.SEVERE, null, ex);
    }
}