/** * Release a specific key using its keycode. * * @param keycode the Java keycode, all available keycode can be found in java.awt.event.KeyEvent * class (VK_A, VK_SPACE, ...) * @see java.awt.event.KeyEvent */ public void keyRelease(int keycode) { /* AltGr does not seems to work with robot, handle it via our * JNI code */ if (keycode == KeyEvent.VK_ALT_GRAPH) { symbolRelease("altgr"); } else { robot.keyRelease(keycode); } }
/** * Release a specific key using its char representation. * * @param key char representation of the key */ public void keyRelease(char key) { /* check for CTRL+X where X is [A-Z] * CTRL+A = 1, A = 65 */ if (key >= 1 && key <= 0x1A) { key = (char) (key + 64); robot.keyRelease(key); return; } if (nativeKeyboard != null) nativeKeyboard.keyRelease(key); }
/** * Press a specific key using its char representation. * * @param key char representation of the key */ public void keyPress(char key) { /* check for CTRL+X where X is [A-Z] * CTRL+A = 1, A = 65 */ if (key >= 1 && key <= 0x1A) { key = (char) (key + 64); robot.keyPress(key); return; } nativeKeyboard.keyPress(key); }
/** * Capture a part of the desktop screen using <tt>java.awt.Robot</tt>. * * @param x x position to start capture * @param y y position to start capture * @param width capture width * @param height capture height * @return <tt>BufferedImage</tt> of a part of the desktop screen or null if Robot problem */ public BufferedImage captureScreen(int x, int y, int width, int height) { BufferedImage img = null; Rectangle rect = null; if (robot == null) { /* Robot has not been created so abort */ return null; } if (logger.isInfoEnabled()) logger.info("Begin capture: " + System.nanoTime()); rect = new Rectangle(x, y, width, height); img = robot.createScreenCapture(rect); if (logger.isInfoEnabled()) logger.info("End capture: " + System.nanoTime()); return img; }
/** * Press a specific key using its keycode. * * @param keycode the Java keycode, all available keycodes can be found in java.awt.event.KeyEvent * class (VK_A, VK_SPACE, ...) * @see java.awt.event.KeyEvent */ public void keyPress(int keycode) { if (OSUtils.IS_WINDOWS || OSUtils.IS_MAC) { /* do not allow modifiers for Windows (as * they are handled in native code with * VkScanCode) and Mac OS X */ if (keycode == KeyEvent.VK_ALT || keycode == KeyEvent.VK_SHIFT || keycode == KeyEvent.VK_ALT_GRAPH) { return; } } /* AltGr does not seems to work with robot, handle it via our * JNI code */ if (keycode == KeyEvent.VK_ALT_GRAPH) { symbolPress("altgr"); } else { robot.keyPress(keycode); } }
/** * Release a mouse button(s). * * @param rotation wheel rotation (could be negative or positive depending on the direction). * @see java.awt.Robot#mouseWheel(int wheelAmt) */ public void mouseWheel(int rotation) { robot.mouseWheel(rotation); }
/** * Move the mouse on the screen. * * @param x x position on the screen * @param y y position on the screen * @see java.awt.Robot#mouseMove(int x, int y) */ public void mouseMove(int x, int y) { robot.mouseMove(x, y); }
/** * Release a mouse button(s). * * @param btns button masks * @see java.awt.Robot#mouseRelease(int btns) */ public void mouseRelease(int btns) { robot.mouseRelease(btns); }
/** * Press a mouse button(s). * * @param btns button masks * @see java.awt.Robot#mousePress(int btns) */ public void mousePress(int btns) { robot.mousePress(btns); }