Ejemplo n.º 1
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);
  }
Ejemplo n.º 2
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);
    }
  }