Exemplo n.º 1
0
  @Override
  public boolean onKeyUp(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK) {
      // We don't want to swallow the back button press
      return false;
    }

    // NOTE: Most keyboards, and specifically the Android default keyboard when
    // entering non-ascii characters, will not trigger KeyEvent events as documented
    // here: http://developer.android.com/reference/android/view/KeyEvent.html

    // Log.e("KeyDown", "------------");
    // Log.e("KeyDown", "keyChar:" + (int) event.getDisplayLabel());
    // Log.e("KeyDown", "utfChar:" + (char)event.getUnicodeChar());
    // Log.e("KeyDown", "intUtfChar:" + event.getUnicodeChar());

    final NetworkPackage np = new NetworkPackage(MousePadPlugin.PACKAGE_TYPE_MOUSEPAD_REQUEST);

    boolean modifier = false;
    if (event.isAltPressed()) {
      np.set("alt", true);
      modifier = true;
    }

    if (Build.VERSION.SDK_INT >= 11) {
      if (event.isCtrlPressed()) {
        np.set("ctrl", true);
        modifier = true;
      }
    }

    if (event.isShiftPressed()) {
      np.set("shift", true);
    }

    int specialKey = SpecialKeysMap.get(keyCode, -1);

    if (specialKey != -1) {
      np.set("specialKey", specialKey);
    } else if (event.getDisplayLabel() != 0 && modifier) {
      // Alt will change the utf symbol to non-ascii characters, we want the plain original letter
      // Since getDisplayLabel will always have a value, we have to check for special keys before
      char keyCharacter = event.getDisplayLabel();
      np.set("key", new String(new char[] {keyCharacter}).toLowerCase());
    } else {
      // A normal key, but still not handled by the KeyInputConnection (happens with numbers)
      np.set("key", new String(new char[] {(char) event.getUnicodeChar()}));
    }

    sendKeyPressPackage(np);
    return true;
  }
Exemplo n.º 2
0
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    char c = event.getDisplayLabel();
    // boolean mute = controls.jAppOnKeyDown(c,keyCode,KeyEvent.keyCodeToString(keyCode));  //TODO
    // if (mute) return false;
    switch (keyCode) {
      case KeyEvent.KEYCODE_BACK:
        boolean mute = controls.jAppOnKeyDown(c, keyCode, KeyEvent.keyCodeToString(keyCode));
        if (!mute) { // continue ...
          onBackPressed();
          return true;
        } else { // exit!
          return false; // caution!! the back_key will not close the App, no more!!
        }

      case KeyEvent.KEYCODE_MENU:
        controls.jAppOnKeyDown(c, keyCode, KeyEvent.keyCodeToString(keyCode));
        break;

      case KeyEvent.KEYCODE_SEARCH:
        controls.jAppOnKeyDown(c, keyCode, KeyEvent.keyCodeToString(keyCode));
        break;

      case KeyEvent.KEYCODE_VOLUME_UP:
        // event.startTracking();  //TODO
        controls.jAppOnKeyDown(c, keyCode, KeyEvent.keyCodeToString(keyCode));
        break;

      case KeyEvent.KEYCODE_VOLUME_DOWN:
        controls.jAppOnKeyDown(c, keyCode, KeyEvent.keyCodeToString(keyCode));
        break;

        /*commented! need SDK API >= 18 [Android 4.3] to compile!*/
        /*
        case KeyEvent.KEYCODE_BRIGHTNESS_DOWN:
            controls.jAppOnKeyDown(c,keyCode,KeyEvent.keyCodeToString(keyCode));
            break;
        case KeyEvent.KEYCODE_BRIGHTNESS_UP:
            controls.jAppOnKeyDown(c,keyCode,KeyEvent.keyCodeToString(keyCode));
            break;
         */

      case KeyEvent.KEYCODE_HEADSETHOOK:
        controls.jAppOnKeyDown(c, keyCode, KeyEvent.keyCodeToString(keyCode));
        break;

        // default:  controls.jAppOnKeyDown(c,keyCode,KeyEvent.keyCodeToString(keyCode));
    }
    return super.onKeyDown(keyCode, event);
  }
 private void logKeyEvent(int keyCode, KeyEvent event, boolean down) {
   String s = down ? "KeyDown event:" : "KeyUp event:";
   s +=
       " action "
           + event.getAction()
           + " keycode "
           + keyCode
           + " "
           + KeyEvent.keyCodeToString(keyCode);
   s += " unicode " + event.getUnicodeChar() + " " + event.getDisplayLabel();
   s += " ScanCode " + event.getScanCode();
   s +=
       " MetaState "
           + event.getMetaState()
           + " Flags "
           + event.getFlags()
           + " modifiers "
           + event.getModifiers();
   s +=
       " source " + printSource(event.getSource()) + " device " + printDevice(event.getDeviceId());
   pushText(s);
 }
Exemplo n.º 4
0
  /**
   * Create a string that describes the extended key code. This string can be shown to the user to
   * indicate the current choice of key.
   *
   * @param extendedKeyCode The key code to describe
   * @return A description of the key code
   */
  private String describeExtendedKeyCode(long extendedKeyCode) {
    if (extendedKeyCode == INVALID_EXTENDED_KEY_CODE) {
      return getContext().getString(R.string.no_key_assigned);
    }

    /* If meta keys are pressed, build a string to represent this combination of keys */
    StringBuilder keystrokeDescriptionBuilder = new StringBuilder();
    if ((extendedKeyCode & (((long) KeyEvent.META_CTRL_ON) << 32)) != 0) {
      keystrokeDescriptionBuilder.append(
          getContext().getString(R.string.key_combo_preference_control_plus));
    }
    if ((extendedKeyCode & (((long) KeyEvent.META_ALT_ON) << 32)) != 0) {
      keystrokeDescriptionBuilder.append(
          getContext().getString(R.string.key_combo_preference_alt_plus));
    }
    if ((extendedKeyCode & (((long) KeyEvent.META_SHIFT_ON) << 32)) != 0) {
      keystrokeDescriptionBuilder.append(
          getContext().getString(R.string.key_combo_preference_shift_plus));
    }

    /* Try to obtain a localized representation of the key */
    KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, (int) extendedKeyCode);
    char displayLabel = keyEvent.getDisplayLabel();
    if (displayLabel != 0 && !Character.isWhitespace(displayLabel)) {
      keystrokeDescriptionBuilder.append(displayLabel);
    } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_SPACE) {
      keystrokeDescriptionBuilder.append(getContext().getString(R.string.name_of_space_bar));
    } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
      keystrokeDescriptionBuilder.append(getContext().getString(R.string.name_of_enter_key));
    } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_TAB) {
      keystrokeDescriptionBuilder.append(getContext().getString(R.string.name_of_tab_key));
    } else {
      /* Fall back on non-localized descriptions */
      keystrokeDescriptionBuilder.append(KeyEvent.keyCodeToString((int) extendedKeyCode));
    }

    return keystrokeDescriptionBuilder.toString();
  }