Example usage for java.awt Robot Robot

List of usage examples for java.awt Robot Robot

Introduction

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

Prototype

public Robot() throws AWTException 

Source Link

Document

Constructs a Robot object in the coordinate system of the primary screen.

Usage

From source file:org.suren.autotest.web.framework.awt.AwtMouse.java

@Override
public void wheel(int num) {
    try {/*w  w  w  .j  av  a 2  s  . c  om*/
        new Robot().mouseWheel(num);
    } catch (AWTException e) {
        e.printStackTrace();
    }
}

From source file:org.suren.autotest.web.framework.awt.AwtKeyboard.java

@Override
public void space() {
    try {//from   ww w  .  j  a va  2  s. c  o m
        Robot robot = new Robot();
        robot.keyPress(KeyEvent.VK_SPACE);
        robot.keyRelease(KeyEvent.VK_SPACE);
    } catch (AWTException e) {
        e.printStackTrace();
    }
}

From source file:org.suren.autotest.web.framework.awt.AwtMouse.java

@Override
public void click() {
    try {//w w  w . ja  v  a  2  s .  co m
        Robot robot = new Robot();
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
    } catch (AWTException e) {
        e.printStackTrace();
    }
}

From source file:org.openqa.selenium.remote.server.SnapshotScreenListener.java

@Override
public void onException(Throwable throwable, WebDriver driver) {
    String encoded;/*from w  w  w . j av  a 2  s. c o m*/
    try {
        workAroundD3dBugInVista();

        Rectangle size = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
        BufferedImage image = new Robot().createScreenCapture(size);

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ImageIO.write(image, "png", outputStream);
        encoded = new String(Base64.encodeBase64(outputStream.toByteArray()), "UTF-8");

        session.attachScreenshot(encoded);
    } catch (Throwable e) {
        System.out.println("e = " + e);
        // Alright. No screen shot. Propogate the original exception
    }
}

From source file:com.qspin.qtaste.testapi.impl.generic.UtilityImpl.java

public void createScreenshot(String fileName) throws QTasteException {
    try {/*from w  w  w  .  j  av a  2s .  c  o  m*/
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle screenRectangle = new Rectangle(screenSize);
        Robot robot = new Robot();
        BufferedImage image = robot.createScreenCapture(screenRectangle);
        ImageIO.write(image, "png", new File(fileName));
    } catch (Exception e) {
        throw new QTasteException("Error in createScreenshot: " + e.getMessage());
    }
}

From source file:com.github.srec.command.ext.ScreenshotCommand.java

@Override
protected Value internalCallMethod(ExecutionContext context, Map<String, Value> params) {
    String modeString = asString(MODE, params, context);
    try {/*  w  ww .  j  av a  2s .  c  om*/
        Mode mode = Mode.valueOf(modeString);
        Robot robot = new Robot();
        switch (mode) {
        case DESKTOP:
            screenshot.captureDesktop(null, robot);
            break;
        case FRAME:
            screenshot.captureFrame(null, robot);
            break;
        case INTERNAL_FRAME:
            String iframeName = asString(IFRAME, params, context);
            if (isBlank(iframeName))
                throw new CommandExecutionException("iframe parameter cannot be blank");
            screenshot.captureInternalFrame(iframeName, null, robot);
            break;
        }
    } catch (IllegalArgumentException e) {
        throw new CommandExecutionException("Invalid mode specified for screenshot command: " + modeString);
    } catch (AWTException e) {
        throw new CommandExecutionException(e);
    }
    return null;
}

From source file:cz.babi.desktop.remoteme.common.Controller.java

/**
 * Init Robot./*from  ww w . j a  va 2s.c o m*/
 * @return If robot is inited.
 */
public boolean initRobot() {
    try {
        robot = new Robot();
    } catch (AWTException awte) {
        if (Common.ERROR)
            LOGGER.error("[TCPClientHandler][Can not create Robot.]", awte);
        return false;
    }

    return true;
}

From source file:com.ariatemplates.seleniumjavarobot.LocalRobotizedBrowserFactory.java

public LocalRobotizedBrowserFactory() {
    try {//from www . ja va2  s.c  om
        robot = new LocalRobot(new Robot());
    } catch (AWTException e) {
        throw new RuntimeException(e);
    }
    numLockStateWorkaround();
}

From source file:info.sugoiapps.xoserver.XOverServer.java

/**
 * Create new MouseServer./*from w ww . ja va  2 s  .  c  om*/
 * Initiate connection to a listen port and create a robot for mouse imitation.
 * @param sf JTextField to modify
 */
public XOverServer(JTextField sf) {
    //switcher = sw;
    hostAddress = null;
    addressReceived = false;
    statusField = sf;
    file = null;
    try {
        server = new ServerSocket(PORT);
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    try {
        rbt = new Robot();
    } catch (AWTException ex) {
        ex.printStackTrace();
    }
}