List of usage examples for java.awt Robot Robot
public Robot() throws AWTException
From source file:io.github.bonigarcia.wdm.test.OpenNewTabChromeTest.java
@Test public void test() throws Exception { // Open URL in default tab driver.get("https://wikipedia.org/"); // If Mac OS X, the key combination is CMD+t, otherwise is CONTROL+t int vkControl = IS_OS_MAC ? VK_META : VK_CONTROL; Robot robot = new Robot(); robot.keyPress(vkControl);/*from w w w .j ava 2 s . com*/ robot.keyPress(VK_T); robot.keyRelease(vkControl); robot.keyRelease(VK_T); // Wait up to 5 seconds to the second tab to be opened WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(numberOfWindowsToBe(2)); // Switch to new tab List<String> windowHandles = new ArrayList<>(driver.getWindowHandles()); System.err.println(windowHandles); driver.switchTo().window(windowHandles.get(1)); // Open other URL in second tab driver.get("https://google.com/"); }
From source file:com.varaneckas.hawkscope.hotkey.X11HotkeyListener.java
/** * Creates the Robot/*from ww w.j a v a 2 s . com*/ * * @return */ private Robot createRobot() { try { return new Robot(); } catch (final AWTException e) { log.error("Could not create Robot", e); return null; } }
From source file:org.suren.autotest.web.framework.selenium.action.SeleniumHover.java
@Override public void hover(Element ele) { WebElement webEle = searchStrategyUtils.findStrategy(WebElement.class, ele).search(ele); if (webEle == null) { logger.warn("can not found element."); return;// www. j a va 2 s .c o m } if (!(ele instanceof FileUpload)) { Dimension size = webEle.getSize(); Point loc = webEle.getLocation(); int toolbarHeight = engine.getToolbarHeight(); int x = size.getWidth() / 2 + loc.getX(); int y = size.getHeight() / 2 + loc.getY() + toolbarHeight; try { new Robot().mouseMove(x, y); } catch (AWTException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:net.librec.util.Systems.java
/** * Capture screen with the input string as file name * * @param fileName a given file name/*from w ww. j av a 2 s . c om*/ * @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()); }
From source file:org.apache.openmeetings.screenshare.job.RemoteJob.java
public RemoteJob() { try {// w w w. j a v a 2 s. c o m robot = new Robot(); robot.setAutoDelay(5); } catch (AWTException e) { log.error("Unexpected error while creating Robot", e); } }
From source file:com.chaosting.product.hotkey.Main.java
@PostConstruct public void run() { logger.info("Checking the license..."); String licFile = ClassLoader.getSystemClassLoader().getResource("").getPath() + LIC_FILE_NAME; if (!LicenseUtil.isLicValid(licFile)) { logger.info("The license is expired. The software will exit."); return;//from w ww . j a v a 2 s . c om } logger.info("The license is OK. Checking the required dll..."); String fileName = OSUtil.getOSArch().contains("86") ? "JIntellitype.dll" : "JIntellitype64.dll"; String dllFile = ClassLoader.getSystemClassLoader().getResource("").getPath() + "lib/" + fileName; JIntellitype.setLibraryLocation(dllFile); if (!JIntellitype.isJIntellitypeSupported()) { logger.info("The OS is not Windows or the dll is not found. The software will exit."); return; } JIntellitype jIntellitype = JIntellitype.getInstance(); logger.info("The dll is ready. Parsing the config now..."); final List<Hotkey> hotkeyList = getHotKeyList(); logger.info("Finish parasing config. Registing the hotkey now..."); for (Hotkey hotkey : hotkeyList) { jIntellitype.registerHotKey(hotkey.getIdentifier(), (hotkey.isModShift() == true ? JIntellitype.MOD_SHIFT : 0) + (hotkey.isModControl() == true ? JIntellitype.MOD_CONTROL : 0) + (hotkey.isModWin() == true ? JIntellitype.MOD_WIN : 0) + (hotkey.isModAlt() == true ? JIntellitype.MOD_ALT : 0), (int) hotkey.getKey()); } try { robot = new Robot(); } catch (AWTException e) { e.printStackTrace(); } jIntellitype.addHotKeyListener(new HotkeyListener() { public void onHotKey(int identifier) { for (Hotkey hotkey : hotkeyList) { if (hotkey.getIdentifier() == identifier) { if (hotkey.getGoal().equalsIgnoreCase("exe")) { if (OSUtil.execute(hotkey.getParam())) { logger.info("Executed the " + hotkey.getParam() + " success."); } else { logger.info("Executed the " + hotkey.getParam() + " faild."); } } else if (hotkey.getGoal().equalsIgnoreCase("out")) { int delay = 100; try { delay = Integer.parseInt(properties.getProperty("delay")); } catch (Exception e) { e.printStackTrace(); } robot.delay(delay); for (char c : hotkey.getParam().toCharArray()) { int keycode = convertAsciiInt2KeycodeInt(c); if (keycode == -1) { logger.info("Unsupport character " + c); } else { if ((int) c >= 65 && (int) c <= 90) { robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(keycode); robot.keyRelease(KeyEvent.VK_SHIFT); robot.keyRelease(keycode); } else { robot.keyPress(keycode); robot.keyRelease(keycode); } } } } break; } } } }); logger.info("All the things get ready."); }
From source file:org.eclipse.jubula.rc.common.driver.KeyTyper.java
/** * Private constructor/* w w w .ja v a 2s.co m*/ * * @throws AWTException if there is a problem creating the Robot. */ private KeyTyper() throws AWTException { m_robot = new Robot(); }
From source file:fxts.stations.trader.ui.ABaseDialog.java
public void componentShown(ComponentEvent aEvent) { try {//from w w w . j a v a2 s . co m UserPreferences preferences = UserPreferences.getUserPreferences(TradeDesk.getInst().getUserName()); JButton button = getRootPane().getDefaultButton(); if (preferences.getBoolean("Mouse.snapDefaultButton") && button != null) { // snap mouse to middle of default button Robot robot = new Robot(); int x = (int) button.getLocationOnScreen().getX(); int y = (int) button.getLocationOnScreen().getY(); int width = (int) button.getSize().getWidth(); int height = (int) button.getSize().getHeight(); int x1 = x + width / 2; int y1 = y + height / 2; robot.mouseMove(x1, y1); } } catch (AWTException e) { e.printStackTrace(); } }
From source file:org.sugarcrm.voodoodriver.Utils.java
/** * Take a screen shot and save it to the specified file. * * @param outputFile file to save the screenshot into * @param reporter {@link Reporter} object for logging errors * @param logOK whether logging to reporter is OK. false if this * is called from a reporter object. * @return whether the screenshot was taken successfully *///from ww w. java2 s. c o m public static boolean takeScreenShot(String outputFile, Reporter reporter, boolean logOK) { Robot r = null; reporter.Log("Taking Screenshot."); File tmp = new File(outputFile); if (tmp.exists() && logOK) { String msg; msg = String.format("Existing screenshot '%s' will be overwritten.", outputFile); reporter.Warn(msg); } try { r = new Robot(); } catch (java.awt.AWTException e) { if (logOK) { reporter.ReportError("Screenshot failed (running headless?)"); reporter.ReportException(e); } return false; } Rectangle rec = new Rectangle(); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); dim.setSize(dim); rec.setSize(dim); BufferedImage img = r.createScreenCapture(rec); try { ImageIO.write(img, "png", new File(outputFile)); } catch (java.io.IOException e) { if (logOK) { reporter.ReportError("Screenshot failed (I/O Error)"); reporter.ReportException(e); } return false; } reporter.Log(String.format("Screenshot file: %s", outputFile)); reporter.Log("Screenshot finished."); return true; }
From source file:com.wet.wired.jsr.recorder.DesktopScreenRecorder.java
public Rectangle initialiseScreenCapture() { try {//from ww w . j av a 2 s.co m robot = new Robot(); } catch (AWTException awe) { awe.printStackTrace(); return null; } return new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); }