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:Capture.java

public static void main(String[] args) {
    JFrame capture = new JFrame();
    capture.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Toolkit kit = Toolkit.getDefaultToolkit();
    final Dimension d = kit.getScreenSize();
    capture.setSize(d);/* www  .java2s. c om*/

    Rectangle rect = new Rectangle(d);
    try {
        Robot robot = new Robot();
        final BufferedImage image = robot.createScreenCapture(rect);
        image.flush();
        JPanel panel = new JPanel() {
            public void paintComponent(Graphics g) {
                g.drawImage(image, 0, 0, d.width, d.height, this);
            }
        };
        panel.setOpaque(false);
        panel.prepareImage(image, panel);
        panel.repaint();
        capture.getContentPane().add(panel);
    } catch (Exception e) {
        e.printStackTrace();
    }

    capture.setVisible(true);
}

From source file:ScreenCapture.java

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

From source file:RobotUtilities.java

public static void sendKeysCombo(String keys[]) {
    try {/*from   ww  w . j av  a2  s.  c om*/

        Robot robot = new Robot();

        Class<?> cl = KeyEvent.class;

        int[] intKeys = new int[keys.length];

        for (int i = 0; i < keys.length; i++) {
            Field field = cl.getDeclaredField(keys[i]);
            intKeys[i] = field.getInt(field);
            robot.keyPress(intKeys[i]);
        }

        for (int i = keys.length - 1; i >= 0; i--)
            robot.keyRelease(intKeys[i]);
    } catch (Throwable e) {
        System.err.println(e);
    }
}

From source file:Main.java

public static Color getPointerColor() throws AWTException {
    Point coordinates = MouseInfo.getPointerInfo().getLocation();
    Robot robot = new Robot();
    return robot.getPixelColor((int) coordinates.getX(), (int) coordinates.getX());
}

From source file:Main.java

/**
 * Press key.//from  ww  w . j  a va 2  s  . c om
 *
 * @param key
 *            the key
 */
public static void pressKey(final int key) {
    try {
        final Robot robot = new Robot();
        robot.keyPress(key);
    } catch (final AWTException e) {
        // ExceptionUtil.handle(e);
    }
}

From source file:Main.java

public Main() {
    try {// w  w w. j a  v a2s  .c  o m
        robot = new Robot();
    } catch (Exception e1) {
        e1.printStackTrace();
    }

    timer = new Timer(3000, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Rectangle size = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
            Image image = robot.createScreenCapture(size);
            label.setIcon(new ImageIcon(image));
            frame.setVisible(true);
        }
    });
    timer.setRepeats(false);

    button.addActionListener(e -> {
        frame.setVisible(false);
        timer.start();
    });

    frame.add(button, BorderLayout.NORTH);
    frame.add(label, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(1024, 768);
    frame.setVisible(true);
}

From source file:com.hp.test.framework.jelly.ClickOKonWinDialogTag.java

@Override
public void doTag(XMLOutput arg0) throws MissingAttributeException {
    logger.info("Started Execution of ClickOkonWinDialogTag");
    WebDriver driver = getSelenium();//from   w  w w.  ja  v a2  s.c  o  m

    try {
        Robot robot = new Robot();

        //Pressky Enter/OK Button
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);

    } catch (AWTException e) {
        logger.error("Exception in the Click OK in Windows dialog" + "\n" + e.getMessage());
    }

    logger.info("Completed Execution of ClickOkonWinDialogTag");
}

From source file:com.hp.test.framework.jelly.SelectSaveandOKonDownloadDialogTag.java

@Override
public void doTag(XMLOutput arg0) throws MissingAttributeException {
    logger.info("Started Execution of SelectSaveandOKonDownloadDialogTag");
    WebDriver driver = getSelenium();/*from   ww w .  j av a2 s  . c  o  m*/

    try {
        Robot robot = new Robot();

        //Pressky ALT+S
        robot.keyPress(KeyEvent.VK_ALT);
        robot.keyPress(KeyEvent.VK_S);

        //Release ALT
        robot.keyRelease(KeyEvent.VK_ALT);

        //Press Enter
        robot.keyPress(KeyEvent.VK_ENTER);

        //Release Enter
        robot.keyRelease(KeyEvent.VK_ENTER);

    } catch (AWTException e) {
        logger.error("Exception in the Save and Ok on Download dialog" + "\n" + e.getMessage());
    }

    logger.info("Completed Execution of SelectSaveandOKonDownloadDialogTag");
}

From source file:KeyboardEmulator.java

public static Robot getKeyboard() throws AWTException {
    if (kb == null) {
        try {//from w w w  . j  a  v a  2s .  c o  m
            setKeyboard(new Robot());
        } catch (AWTException e) {
        }
    }
    return kb;
}

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

@Override
public void enter() {
    try {/*  w w  w  .j  av  a 2 s  . c  o  m*/
        Robot robot = new Robot();
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
    } catch (AWTException e) {
        e.printStackTrace();
    }
}