// press Escape programatically - the print dialog must have focus, obviously Robot r = new Robot(); r.keyPress(KeyEvent.VK_ESCAPE); r.keyRelease(KeyEvent.VK_ESCAPE);
/** * Capture screen with the input string as file name * * @param fileName a given file name * @throws Exception if error occurs */ public static void captureScreen(String fileName) throws Exception { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle screenRectangle = new Rectangle(screenSize); Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(screenRectangle); File file = new File(fileName); ImageIO.write(image, "png", file); LOG.debug("A screenshot is captured to: " + file.getPath()); }
int retVal = container.open(url + fileName, IContainer.Type.WRITE, containerFormat_live); if (retVal < 0) { System.err.println("Could not open output container for live stream"); System.exit(1); coder.setHeight(height); coder.setWidth(width); System.out.println("[ENCODER] video size is " + width + "x" + height); coder.setFlag(IStreamCoder.Flags.FLAG_QSCALE, true); coder.setGlobalQuality(0); props.load(is); } catch (IOException e) { System.err.println("You need the libx264-normal.ffpreset file from the Xuggle distribution in your classpath."); System.exit(1); int i = 0; try { Robot robot = new Robot(); while (i < framesToEncode) { BufferedImage image = robot.createScreenCapture(new Rectangle(x, y, width, height));
myRobot = new Robot(); } catch (AWTException e) { e.printStackTrace(); myRobot.keyPress((int) myStringBuilder.charAt(i)); myRobot.keyRelease((int) myStringBuilder.charAt(i)); System.out.println(TimeStamp + ": scanned input received:" + myStringBuilder.toString()); System.out.println(TimeStamp + ": " + comPort + " " + myCommPortIdentifier); System.out.println(TimeStamp + ": msg1 - " + e);
r.mouseMove(x, y); r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); r.mouseMove(x, y); if (nr == 1) r.mousePress(InputEvent.BUTTON1_MASK); Robot r = new Robot(); doLeftMouseClick(r, 272, 241); r.delay(1000); doLeftMouseClick(r, 272, 241); r.keyPress(KeyEvent.SHIFT_MASK); doLeftMouseClickEvent(r, 272, 241, 1); doLeftMouseClickEvent(r, 529, 242, 2); r.keyRelease(KeyEvent.SHIFT_MASK); r.keyPress(KeyEvent.CTRL_MASK); r.keyPress(KeyEvent.VK_C); r.keyRelease(KeyEvent.CTRL_MASK);
Robot robot = new Robot(); while (working) robot.keyRelease(KeyEvent.VK_ALT); robot.keyRelease(KeyEvent.VK_TAB); frame.requestFocus(); try { Thread.sleep(10); } catch(Exception) {}
public static void saveScreenshot() throws Exception { System.out.println("Saving screenshot!"); Rectangle screenRect = new Rectangle(Display.getX(), Display.getY(), Display.getWidth(), Display.getHeight()); BufferedImage capture = new Robot().createScreenCapture(screenRect); ImageIO.write(capture, "png", new File("doc/saved/screenshot.png")); }
Robot robot = new Robot(); BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); ImageIO.write(screenShot, "JPG", new File("d:\\"+formatter.format(now.getTime())+".jpg")); System.out.println(formatter.format(now.getTime()));
Robot robot = new Robot(); System.out.println("You have 2 seconds to jump to the target window..."); Thread.sleep(2000); robot.keyPress( KeyEvent.VK_A); robot.keyRelease( KeyEvent.VK_A); robot.keyPress( KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_A); robot.keyRelease( KeyEvent.VK_SHIFT); robot.keyRelease( KeyEvent.VK_A); Thread.sleep(2000);
public static void main(String[] args){ Robot bot = new Robot(); // if Robot constructor declared AWTException // the class instance initialization line should // be wrapped in the try-catch block as well try{ bot.mouseMove(50, 50);//mouseMove might throw AWTException }catch( AWTException awte){ System.err.println("Exception thrown:" + awte.getMessage()); } }
driver.findElement(By.id("SWFUpload_0")).click(); Robot r = new Robot(); r.keyPress(KeyEvent.VK_C); // C r.keyRelease(KeyEvent.VK_C); r.keyPress(KeyEvent.VK_COLON); // : (colon) r.keyRelease(KeyEvent.VK_COLON); r.keyPress(KeyEvent.VK_SLASH); // / (slash) r.keyRelease(KeyEvent.VK_SLASH); // etc. for the whole file path r.keyPress(KeyEvent.VK_ENTER); // confirm by pressing Enter in the end r.keyRelease(KeyEvent.VK_ENTER);
private void createShadowPicture(BufferedImage image) { int width = image.getWidth(); int height = image.getHeight(); int extra = 0; if (System.getProperty("os.name").equalsIgnoreCase("Windows XP")) { extra = 14; // Only create shadow if Windows XP (avoids double shadow in Mac OS; not tested for other OSes) } setSize(new Dimension(width + extra, height + extra)); setLocationRelativeTo(null); Rectangle windowRect = getBounds(); splash = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) splash.getGraphics(); try { Robot robot = new Robot(getGraphicsConfiguration().getDevice()); BufferedImage capture = robot.createScreenCapture(new Rectangle(windowRect.x, windowRect.y, windowRect.width + extra, windowRect.height + extra)); g2.drawImage(capture, null, 0, 0); } catch (AWTException e) { } BufferedImage shadow = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB); Graphics g = shadow.getGraphics(); g.setColor(new Color(0.0f, 0.0f, 0.0f, 0.3f)); g.fillRoundRect(6, 6, width, height, 12, 12); g2.drawImage(shadow, getBlurOp(7), 0, 0); g2.drawImage(image, 0, 0, this); }