Example usage for java.awt Robot mouseWheel

List of usage examples for java.awt Robot mouseWheel

Introduction

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

Prototype

public synchronized void mouseWheel(int wheelAmt) 

Source Link

Document

Rotates the scroll wheel on wheel-equipped mice.

Usage

From source file:Main.java

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

    robot.mouseMove(200, 200);/*  w w  w  .ja  va2 s  .  c om*/

    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.mouseWheel(-100);
}

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

/**
 * Fires a set of java robot mouse events into the webpage.
 * /*w  w w  .  j a v  a 2 s .  com*/
 * @param commands
 *            the commands
 * @throws Exception
 *             the exception
 */

private void fireMouseEvent(final String commands) throws Exception {

    String[] commandSet = commands.split("\\|");
    Robot robot = new Robot();
    final int optimumPauseBetweenKeyCombs = 10;
    final int f11KeyCode = KeyEvent.VK_F11;
    for (String fullCommand : commandSet) {
        Utils.pause(retryInterval);
        int commandIndex = 0;
        int inputIndex = 1;
        String command = fullCommand.split("=")[commandIndex];
        String input = fullCommand.split("=")[inputIndex];

        if ("MOVE".equalsIgnoreCase(command)) {

            String[] coords = input.split(",");
            int resolutionWidth = Integer.parseInt(coords[0]);
            int resolutionHeight = Integer.parseInt(coords[inputIndex]);
            int x = Integer.parseInt(coords[inputIndex + 1]);
            int y = Integer.parseInt(coords[inputIndex + 2]);

            int xCordinateAutual = (int) calWidth(resolutionWidth, x);
            int yCordinateAutual = (int) calHight(resolutionHeight, y);

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

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

            robot.keyPress(f11KeyCode);
            Utils.pause(optimumPauseBetweenKeyCombs);
            robot.keyRelease(f11KeyCode);

        } else if ("SCROLL".equalsIgnoreCase(command)) {

            robot.mouseWheel(Integer.parseInt(input));

        } else if ("wait".equalsIgnoreCase(command)) {

            Utils.pause(Integer.parseInt(input));
        } else {
            throw new Exception("Command " + command);
        }
    }
}

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

/**
 * Fires a set of java robot mouse events into the webpage.
 * /* w  w  w .  j a va2  s  .co  m*/
 * @param commands
 *            the commands
 * @throws Exception
 *             the exception
 */

private void fireMouseEvent(final String commands) throws Exception {

    String[] commandSet = commands.split("\\|");
    Robot robot = getRobot();
    final int optimumPauseBetweenKeyCombs = 10;
    final int f11KeyCode = KeyEvent.VK_F11;
    for (String fullCommand : commandSet) {
        sleep(retryInterval);
        int commandIndex = 0;
        int inputIndex = 1;
        String command = fullCommand.split("=")[commandIndex];
        String input = fullCommand.split("=")[inputIndex];

        if ("MOVE".equalsIgnoreCase(command)) {

            String[] coords = input.split(",");
            int resolutionWidth = Integer.parseInt(coords[0]);
            int resolutionHeight = Integer.parseInt(coords[inputIndex]);
            int x = Integer.parseInt(coords[inputIndex + 1]);
            int y = Integer.parseInt(coords[inputIndex + 2]);

            int xCordinateAutual = (int) calWidth(resolutionWidth, x);
            int yCordinateAutual = (int) calHight(resolutionHeight, y);

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

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

            robot.keyPress(f11KeyCode);
            sleep(optimumPauseBetweenKeyCombs);
            robot.keyRelease(f11KeyCode);

        } else if ("SCROLL".equalsIgnoreCase(command)) {

            robot.mouseWheel(Integer.parseInt(input));

        } else if ("wait".equalsIgnoreCase(command)) {

            super.sleep(Integer.parseInt(input));
        } else {
            throw new Exception("Command " + command);
        }
    }
}