Example #1
0
  // Key events
  @Override
  public boolean onKey(View v, int keyCode, KeyEvent event) {
    // Dispatch the different events depending on where they come from
    // Some SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
    // So, we try to process them as DPAD or GAMEPAD events first, if that fails we try them as
    // KEYBOARD

    if ((event.getSource() & InputDevice.SOURCE_GAMEPAD) != 0
        || (event.getSource() & InputDevice.SOURCE_DPAD) != 0) {
      if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (SDLActivity.onNativePadDown(event.getDeviceId(), keyCode) == 0) {
          return true;
        }
      } else if (event.getAction() == KeyEvent.ACTION_UP) {
        if (SDLActivity.onNativePadUp(event.getDeviceId(), keyCode) == 0) {
          return true;
        }
      }
    }

    if ((event.getSource() & InputDevice.SOURCE_KEYBOARD) != 0) {
      if (event.getAction() == KeyEvent.ACTION_DOWN) {
        // Log.v("SDL", "key down: " + keyCode);
        SDLActivity.onNativeKeyDown(keyCode);
        return true;
      } else if (event.getAction() == KeyEvent.ACTION_UP) {
        // Log.v("SDL", "key up: " + keyCode);
        SDLActivity.onNativeKeyUp(keyCode);
        return true;
      }
    }

    return false;
  }
Example #2
0
  // Key events
  public boolean onKey(View v, int keyCode, KeyEvent event) {

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
      // Log.v("SDL", "key down: " + keyCode);
      SDLActivity.onNativeKeyDown(keyCode);
      return true;
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
      // Log.v("SDL", "key up: " + keyCode);
      SDLActivity.onNativeKeyUp(keyCode);
      return true;
    }

    return false;
  }
Example #3
0
  // Key events
  @Override
  public boolean onKey(View v, int keyCode, KeyEvent event) {

    // Urho3D: let the home & volume keys be handled by the system
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
        || keyCode == KeyEvent.KEYCODE_VOLUME_UP
        || keyCode == KeyEvent.KEYCODE_HOME) return false;

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
      // Log.v("SDL", "key down: " + keyCode);
      SDLActivity.onNativeKeyDown(keyCode);
      return true;
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
      // Log.v("SDL", "key up: " + keyCode);
      SDLActivity.onNativeKeyUp(keyCode);
      return true;
    }

    return false;
  }
Example #4
0
  @Override
  public boolean sendKeyEvent(KeyEvent event) {

    /*
     * This handles the keycodes from soft keyboard (and IME-translated
     * input from hardkeyboard)
     */
    int keyCode = event.getKeyCode();
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
      if (event.isPrintingKey()) {
        commitText(String.valueOf((char) event.getUnicodeChar()), 1);
      }
      SDLActivity.onNativeKeyDown(keyCode);
      return true;
    } else if (event.getAction() == KeyEvent.ACTION_UP) {

      SDLActivity.onNativeKeyUp(keyCode);
      return true;
    }
    return super.sendKeyEvent(event);
  }
Example #5
0
  @Override
  public boolean onKey(View v, int keyCode, KeyEvent event) {

    // This handles the hardware keyboard input
    if (event.isPrintingKey()) {
      if (event.getAction() == KeyEvent.ACTION_DOWN) {
        ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1);
      }
      return true;
    }

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
      SDLActivity.onNativeKeyDown(keyCode);
      return true;
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
      SDLActivity.onNativeKeyUp(keyCode);
      return true;
    }

    return false;
  }