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

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

    robot.mouseMove(200, 200);/*  w w w  .  jav a 2s .  c o  m*/

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

From source file:Main.java

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

    Robot r = new Robot();
    r.mouseMove(35, 35);/*from   w w w  . j a  v a2 s .  com*/
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    Thread.sleep(50);
    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.delay(3000);//from   w w w  . j  a v a2  s.  c o  m

    robot.keyPress(KeyEvent.VK_Q);
    robot.keyPress(KeyEvent.VK_W);
    robot.keyPress(KeyEvent.VK_E);
    robot.keyPress(KeyEvent.VK_R);
    robot.keyPress(KeyEvent.VK_T);
    robot.keyPress(KeyEvent.VK_Y);
}

From source file:Main.java

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

    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Robot robot = new Robot();
    int x = 100;//  w  w  w.  jav  a 2 s. co  m
    int y = 100;
    int width = 200;
    int height = 200;
    Rectangle area = new Rectangle(x, y, width, height);
    BufferedImage bufferedImage = robot.createScreenCapture(area);

    area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    bufferedImage = robot.createScreenCapture(area);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Robot robot = new Robot();
    int x = 100;/*from  w  w  w .j  a v a2s .c  o  m*/
    int y = 100;
    int width = 200;
    int height = 200;
    Rectangle area = new Rectangle(x, y, width, height);
    BufferedImage bufferedImage = robot.createScreenCapture(area);

    // Capture the whole screen
    area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    bufferedImage = robot.createScreenCapture(area);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_PRINTSCREEN);
    robot.delay(40);//  w w  w.jav a  2  s .  com
    robot.keyRelease(KeyEvent.VK_PRINTSCREEN);
    robot.delay(404);

    Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
    DataFlavor[] flavors = cb.getAvailableDataFlavors();
    for (DataFlavor flavor : flavors) {
        if (flavor.toString().indexOf("java.awt.Image") <= 0) {
            continue;
        }
        Image i = (Image) cb.getData(flavor);
        BufferedImage bi = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_RGB);
        Graphics2D g = bi.createGraphics();
        g.drawImage(i, 0, 0, null);
        g.dispose();
        ImageIO.write(bi, "png", new File("c:/Java_Dev/test.png"));
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    BufferedImage image = robot.createScreenCapture(new Rectangle(d));
    BufferedImage sub = image.getSubimage(0, 0, 400, 400);
    File f = new File("SubImage.png");
    ImageIO.write(sub, "png", f);
    final ImageIcon im = new ImageIcon(f.toURI().toURL());

    Runnable r = new Runnable() {

        @Override/*w  w  w  .  ja v  a 2 s.co  m*/
        public void run() {
            JOptionPane.showMessageDialog(null, new JLabel(im));
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:Main.java

public static void main(String[] arg) throws Exception {
    Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
    Robot robot = new Robot();

    BufferedImage image = robot/*from   w ww .  j  a v a  2s.  c  o m*/
            .createScreenCapture(new Rectangle(0, 0, (int) screenDim.getWidth(), (int) screenDim.getHeight()));

    JWindow window = new JWindow(new JFrame());
    window.getContentPane().setLayout(new BorderLayout());
    window.getContentPane().add(BorderLayout.CENTER, new JLabel(new ImageIcon(image)));
    window.pack();
    window.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    BufferedImage screen = robot.createScreenCapture(new Rectangle(screenSize));

    new ScreenCaptureRectangle(screen);
}