@Override public IDevice start(Object... args) { if (SX.isSetSXLOCALDEVICE()) { log.trace("already started"); return SX.getSXLOCALDEVICE(); } else { log.trace("starting"); if (0 < initMonitors()) { try { robot = new LocalRobot(); } catch (AWTException e) { log.terminate(1, "LocalRobot: %s", e.getMessage()); } } else { log.terminate(1, "No monitors - might be headless %s"); } if (SX.isOption("SX.withHook", false)) { hook = (HookDevice) new HookDevice().start(); } } return this; }
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()); } }
private static void setMouseRobot() { try { if (globalRobot == null && !GraphicsEnvironment.isHeadless()) { globalRobot = new RobotDesktop(); } } catch (AWTException e) { Debug.error("Can't initialize global Robot for Mouse: " + e.getMessage()); } }
+ e.getMessage()); mode = "awt";
void cancelMonitorTask() { timer.cancel(); try { Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_Q); robot.keyRelease(KeyEvent.VK_Q); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); } catch (java.awt.AWTException e) { logger.severe(strings.get("awt.error", e.getMessage())); } }
private static final void init() { try { Input.keyboard = new Keyboard(); mouse = new Mouse(); if (Game.config().input().isGamepadSupport()) { gamePads = new CopyOnWriteArrayList<>(); gamePadManager = new GamepadManager(); } } catch (AWTException e) { log.log(Level.SEVERE, e.getMessage(), e); } }
@Override public void actionPerformed(ActionEvent e) { try { // Obtain the listing of selected macros Macro[] macros = demo.getSelectedMacros(true); // Obtain the reference point for playing macros Point offset = recordComponent.getLocationOnScreen(); // Obtain hide/show macros Macro hideMacro = recordComponent.getHideFrameMacro(); Macro showMacro = recordComponent.getShowFrameMacro(); // Add the hide to beginning and show to end Macro[] runMacros = new Macro[macros.length + 2]; runMacros[0] = hideMacro; for (int i = 0; i < macros.length; i++) { runMacros[i + 1] = macros[i]; } runMacros[runMacros.length - 1] = showMacro; // Play the macros (hiding and showing frame) MacroPlayer player = new MacroPlayer(5, offset); player.play(runMacros); } catch (AWTException ex) { // Indicate failure to initiate playing macros JOptionPane.showMessageDialog(frame, "Failed to initiate player: " + ex.getMessage() + " [" + ex.getClass().getSimpleName() + "]", "Player error", JOptionPane.ERROR_MESSAGE); } } });
robot.keyRelease(KeyEvent.VK_ENTER); } catch (AWTException e) { throw new ScenarioException("could not initialize robot to upload file: " + e.getMessage());
robot.keyRelease(KeyEvent.VK_ENTER); } catch (AWTException e) { throw new ScenarioException("could not initialize robot to upload file: " + e.getMessage());
/** * write text to desktop. * @param textToWrite text to write * @return */ public static void writeToDesktop(String textToWrite, DriverMode driverMode, SeleniumGridConnector gridConnector) { if (driverMode == DriverMode.LOCAL) { try { Keyboard keyboard = new Keyboard(); keyboard.typeKeys(textToWrite); } catch (AWTException e) { throw new ScenarioException("writeToDesktop: could not initialize robot to type keys: " + e.getMessage()); } } else if (driverMode == DriverMode.GRID && gridConnector != null) { gridConnector.writeText(textToWrite); } else { throw new ScenarioException("driver supports sendKeysToDesktop only in local and grid mode"); } }
private void mode2() { final String netplanURL = parameters.get("netplan"); try { Robot robot = new Robot(); // Close table window robot.type(KeyEvent.VK_F4, KeyEvent.VK_ALT); robot.delay(200); // Open up load menu robot.type(KeyEvent.VK_O, KeyEvent.VK_CONTROL); robot.delay(200); robot.copy(netplanURL); robot.paste(); robot.type(KeyEvent.VK_ENTER); } catch (AWTException e) { throw new RuntimeException(e.getMessage()); } } }
/** * write text to desktop. * @param textToWrite text to write * @return */ public static void writeToDesktop(String textToWrite, DriverMode driverMode, SeleniumGridConnector gridConnector) { if (driverMode == DriverMode.LOCAL) { try { Keyboard keyboard = new Keyboard(); keyboard.typeKeys(textToWrite); } catch (AWTException e) { throw new ScenarioException("writeToDesktop: could not initialize robot to type keys: " + e.getMessage()); } } else if (driverMode == DriverMode.GRID && gridConnector != null) { gridConnector.writeText(textToWrite); } else { throw new ScenarioException("driver supports sendKeysToDesktop only in local and grid mode"); } }
/** * Upload file typing file path directly * @param tempFile */ public static void uploadFileUsingKeyboardTyping(File tempFile) { try { Keyboard keyboard = new Keyboard(); Robot robot = keyboard.getRobot(); WaitHelper.waitForSeconds(1); // // Press Enter // robot.keyPress(KeyEvent.VK_ENTER); // // // Release Enter // robot.keyRelease(KeyEvent.VK_ENTER); keyboard.typeKeys(tempFile.getAbsolutePath()); WaitHelper.waitForSeconds(1); // Press Enter robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); } catch (AWTException e) { throw new ScenarioException("could not initialize robot to upload file typing keys: " + e.getMessage()); } }
/** * Upload file typing file path directly * @param tempFile */ public static void uploadFileUsingKeyboardTyping(File tempFile) { try { Keyboard keyboard = new Keyboard(); Robot robot = keyboard.getRobot(); WaitHelper.waitForSeconds(1); // // Press Enter // robot.keyPress(KeyEvent.VK_ENTER); // // // Release Enter // robot.keyRelease(KeyEvent.VK_ENTER); keyboard.typeKeys(tempFile.getAbsolutePath()); WaitHelper.waitForSeconds(1); // Press Enter robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); } catch (AWTException e) { throw new ScenarioException("could not initialize robot to upload file typing keys: " + e.getMessage()); } }
/** * right clic at coordinates on desktop. Coordinates are from screen point of view * @param x * @param y */ public static void rightClicOnDesktopAt(int x, int y, DriverMode driverMode, SeleniumGridConnector gridConnector) { if (driverMode == DriverMode.LOCAL) { try { Robot robot = new Robot(); moveMouse(robot, x, y); robot.mousePress(InputEvent.BUTTON2_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON2_DOWN_MASK); } catch (AWTException e) { throw new ScenarioException("rightClicOnDesktopAt: problem using Robot: " + e.getMessage()); } } else if (driverMode == DriverMode.GRID && gridConnector != null) { gridConnector.rightClic(x, y); } else { throw new ScenarioException("driver supports sendKeysToDesktop only in local and grid mode"); } }
/** * Left clic at coordinates on desktop. Coordinates are from screen point of view * @param x * @param y */ public static void leftClicOnDesktopAt(int x, int y, DriverMode driverMode, SeleniumGridConnector gridConnector) { if (driverMode == DriverMode.LOCAL) { try { Robot robot = new Robot(); moveMouse(robot, x, y); robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); } catch (AWTException e) { throw new ScenarioException("leftClicOnDesktopAt: problem using Robot: " + e.getMessage()); } } else if (driverMode == DriverMode.GRID && gridConnector != null) { gridConnector.leftClic(x, y); } else { throw new ScenarioException("driver supports sendKeysToDesktop only in local and grid mode"); } }
/** * Left clic at coordinates on desktop. Coordinates are from screen point of view * @param x * @param y */ public static void leftClicOnDesktopAt(int x, int y, DriverMode driverMode, SeleniumGridConnector gridConnector) { if (driverMode == DriverMode.LOCAL) { try { Robot robot = new Robot(); moveMouse(robot, x, y); robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); } catch (AWTException e) { throw new ScenarioException("leftClicOnDesktopAt: problem using Robot: " + e.getMessage()); } } else if (driverMode == DriverMode.GRID && gridConnector != null) { gridConnector.leftClic(x, y); } else { throw new ScenarioException("driver supports sendKeysToDesktop only in local and grid mode"); } }
/** * right clic at coordinates on desktop. Coordinates are from screen point of view * @param x * @param y */ public static void rightClicOnDesktopAt(int x, int y, DriverMode driverMode, SeleniumGridConnector gridConnector) { if (driverMode == DriverMode.LOCAL) { try { Robot robot = new Robot(); moveMouse(robot, x, y); robot.mousePress(InputEvent.BUTTON2_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON2_DOWN_MASK); } catch (AWTException e) { throw new ScenarioException("rightClicOnDesktopAt: problem using Robot: " + e.getMessage()); } } else if (driverMode == DriverMode.GRID && gridConnector != null) { gridConnector.rightClic(x, y); } else { throw new ScenarioException("driver supports sendKeysToDesktop only in local and grid mode"); } }
/** * send keys to desktop * This is useful for typing special keys like ENTER * @param keys */ public static void sendKeysToDesktop(List<Integer> keyCodes, DriverMode driverMode, SeleniumGridConnector gridConnector) { if (driverMode == DriverMode.LOCAL) { try { Robot robot = new Robot(); WaitHelper.waitForSeconds(1); for (Integer key: keyCodes) { robot.keyPress(key); robot.keyRelease(key); } } catch (AWTException e) { throw new ScenarioException("could not initialize robot to type keys: " + e.getMessage()); } } else if (driverMode == DriverMode.GRID && gridConnector != null) { gridConnector.sendKeysWithKeyboard(keyCodes); } else { throw new ScenarioException("driver supports sendKeysToDesktop only in local and grid mode"); } }
/** * send keys to desktop * This is useful for typing special keys like ENTER * @param keys */ public static void sendKeysToDesktop(List<Integer> keyCodes, DriverMode driverMode, SeleniumGridConnector gridConnector) { if (driverMode == DriverMode.LOCAL) { try { Robot robot = new Robot(); WaitHelper.waitForSeconds(1); for (Integer key: keyCodes) { robot.keyPress(key); robot.keyRelease(key); } } catch (AWTException e) { throw new ScenarioException("could not initialize robot to type keys: " + e.getMessage()); } } else if (driverMode == DriverMode.GRID && gridConnector != null) { gridConnector.sendKeysWithKeyboard(keyCodes); } else { throw new ScenarioException("driver supports sendKeysToDesktop only in local and grid mode"); } }