Example usage for java.awt Robot mouseRelease

List of usage examples for java.awt Robot mouseRelease

Introduction

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

Prototype

public synchronized void mouseRelease(int buttons) 

Source Link

Document

Releases one or more mouse buttons.

Usage

From source file:com.peter.mavenrunner.MavenRunnerTopComponent.java

private void projectTreeKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_projectTreeKeyReleased
    if (evt.getKeyCode() == 525) {
        //         treePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
        try {/*  w  w  w .ja va 2 s. co m*/
            Robot robot = new Robot();
            robot.mousePress(InputEvent.BUTTON3_MASK);
            robot.mouseRelease(InputEvent.BUTTON3_MASK);
        } catch (AWTException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}

From source file:com.virtusa.isq.rft.runtime.RFTCommandBase.java

/**
 * Performs a Java robot click on the specific coordinates. <br>
 * /*  www .ja v a  2s. co  m*/
 * @param resolution
 *            the resolution
 * @param coordinates
 *            the coordinates
 * @param waitTime
 *            the wait time
 * @throws Exception
 *             the exception
 */
@Override
public final void mouseMoveAndClick(final String resolution, final String coordinates, final String waitTime) {

    String res = resolution;
    final int f11KeyCode = KeyEvent.VK_F11;
    final int optimumPauseBetweenkeyCombs = 10;
    String[] resArr = res.split(",");
    String[] coordinatesArr = coordinates.split(",");

    float screenWidht = Float.parseFloat(resArr[0]);
    float screeHigt = Float.parseFloat(resArr[1]);
    float xCordinate = Float.parseFloat(coordinatesArr[0]);
    float yCordinate = Float.parseFloat(coordinatesArr[1]);
    String command = "";

    if (coordinatesArr.length > 2) {

        command = coordinatesArr[2];
    }

    Robot robot = null;
    try {
        robot = new Robot();
    } catch (AWTException e) {
        e.printStackTrace();
    }

    Utils.pause(Integer.parseInt(waitTime));

    int xCordinateAutual = (int) calWidth(screenWidht, xCordinate);
    int yCordinateAutual = (int) calHight(screeHigt, yCordinate);

    robot.keyPress(f11KeyCode);
    robot.delay(optimumPauseBetweenkeyCombs);
    robot.keyRelease(f11KeyCode);
    Utils.pause(retryInterval);

    // Mouse Move
    robot.mouseMove(xCordinateAutual, yCordinateAutual);

    // Click
    if ("".equals(command)) {

        robot.mousePress(InputEvent.BUTTON1_MASK);
        Utils.pause(retryInterval);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);

        reportResults(ReportLogger.ReportLevel.SUCCESS, "Mouse Move And Click", "Success",
                "Resolution : " + res);

    } else if ("dclick".equals(command.toLowerCase(Locale.getDefault()))) {

        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        final int optimumPauseBetweenDclick = 500;
        robot.delay(optimumPauseBetweenDclick);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);

        reportResults(true, ReportLogger.ReportLevel.SUCCESS, "Mouse Move And Click", "Success",
                "Resolution : " + res);

    }

    robot.keyPress(f11KeyCode);
    robot.delay(optimumPauseBetweenkeyCombs);
    robot.keyRelease(f11KeyCode);
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

/**
 * Performs a Java robot click on the specific coordinates. <br>
 * //w ww. ja  v a 2  s  .c o  m
 * @param resolution
 *            the resolution
 * @param coordinates
 *            the coordinates
 * @param waitTime
 *            the wait time
 * @throws Exception
 *             the exception
 */

public final void mouseMoveAndClick(final String resolution, final String coordinates, final String waitTime)
        throws Exception {

    String res = resolution;
    final int f11KeyCode = KeyEvent.VK_F11;
    final int optimumPauseBetweenkeyCombs = 10;
    if (res.startsWith("prop=")) {

        String resolutionFromProp = getExecProps().getProperty((res.split("prop=")[1]));
        if (resolutionFromProp != null) {
            res = resolutionFromProp;
        } else {
            reportresult(true, "MOUSE MOVE AND CLICK:", "FAILED",
                    "MOUSE MOVE AND CLICK command: Invalid property key value passed : " + res);
            checkTrue(false, true, "MOUSE MOVE AND CLICK command: Invalid property key value passed : " + res);
        }
    }

    float screenWidht = 0;
    float screeHigt = 0;
    try {
        String[] resArr = res.split(",");
        screenWidht = Float.parseFloat(resArr[0]);
        screeHigt = Float.parseFloat(resArr[1]);
    } catch (Exception e) {

        getLog().error(e);
        reportresult(true, "MOUSE MOVE AND CLICK:", "FAILED",
                "MOUSE MOVE AND CLICK command: Invalid input value passed for resolution : " + res);
        checkTrue(false, true,
                "MOUSE MOVE AND CLICK command: Invalid input value passed for resolution : " + res);
    }

    String[] coordinatesArr = coordinates.split(",");
    float xCordinate = 0;
    float yCordinate = 0;
    try {
        xCordinate = Float.parseFloat(coordinatesArr[0]);
        yCordinate = Float.parseFloat(coordinatesArr[1]);
    } catch (Exception e) {

        getLog().error(e);
        reportresult(true, "MOUSE MOVE AND CLICK:", "FAILED",
                "MOUSE MOVE AND CLICK command: Invalid input value passed for coordinates : " + coordinates);
        checkTrue(false, true,
                "MOUSE MOVE AND CLICK command: Invalid input value passed for coordinates : " + coordinates);
    }
    String command = "";

    if (coordinatesArr.length > 2) {

        command = coordinatesArr[2];
    }

    Robot robot = new Robot();

    super.sleep(Integer.parseInt(waitTime));

    int xCordinateAutual = (int) calWidth(screenWidht, xCordinate);
    int yCordinateAutual = (int) calHight(screeHigt, yCordinate);

    robot.keyPress(f11KeyCode);
    robot.delay(optimumPauseBetweenkeyCombs);
    robot.keyRelease(f11KeyCode);
    sleep(retryInterval);

    // Mouse Move
    robot.mouseMove(xCordinateAutual, yCordinateAutual);

    // Click
    if ("".equals(command)) {

        robot.mousePress(InputEvent.BUTTON1_MASK);
        sleep(retryInterval);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        reportresult(true, "MOUSE MOVE AND CLICK : ", "PASSED",
                "MOUSE MOVE AND CLICK command: Resolution : " + res);

    } else if ("dclick".equals(command.toLowerCase(Locale.getDefault()))) {

        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        final int optimumPauseBetweenDclick = 500;
        robot.delay(optimumPauseBetweenDclick);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);

        reportresult(true, "MOUSE MOVE AND DOUBLE CLICK : ", "PASSED",
                "MOUSE MOVE AND DOUBLE CLICK command: Resolution: " + res);
        checkTrue(false, true, "MOUSE MOVE AND CLICK command: Resolution: " + res);

    }

    robot.keyPress(f11KeyCode);
    robot.delay(optimumPauseBetweenkeyCombs);
    robot.keyRelease(f11KeyCode);
}