예제 #1
0
 /**
  * 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);
   }
 }
예제 #2
0
  /**
   * 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);
  }
예제 #3
0
  /**
   * 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;
  }
예제 #5
0
  /**
   * 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);
    }
  }
예제 #6
0
 /**
  * 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);
 }
예제 #7
0
 /**
  * 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);
 }
예제 #8
0
 /**
  * Release a mouse button(s).
  *
  * @param btns button masks
  * @see java.awt.Robot#mouseRelease(int btns)
  */
 public void mouseRelease(int btns) {
   robot.mouseRelease(btns);
 }
예제 #9
0
 /**
  * Press a mouse button(s).
  *
  * @param btns button masks
  * @see java.awt.Robot#mousePress(int btns)
  */
 public void mousePress(int btns) {
   robot.mousePress(btns);
 }