// 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; }
@Override public boolean onKeyMultiple(int keyCode, int count, KeyEvent event) { if (keyCode != KeyEvent.KEYCODE_UNKNOWN || event.getAction() != KeyEvent.ACTION_MULTIPLE) return super.onKeyMultiple(keyCode, count, event); if (event.getCharacters() != null) { int utf8Char = event.getCharacters().codePointAt(0); handleKeyDown(host, utf8Char, utf8Char); return true; } return false; }
// 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; }
@Override public boolean onKeyMultiple(final int inKeyCode, int repeatCount, KeyEvent event) { String s = event.getCharacters(); if (s == null || s.length() == 0) return super.onKeyMultiple(inKeyCode, repeatCount, event); final char[] cc = s.toCharArray(); int cnt = 0; for (int i = cc.length; --i >= 0; cnt += cc[i] != 0 ? 1 : 0) ; if (cnt == 0) return super.onKeyMultiple(inKeyCode, repeatCount, event); final Activity me = this; queueEvent( new Runnable() { // This method will be called on the rendering thread: public void run() { for (int i = 0, n = cc.length; i < n; i++) { int keyCode; if ((keyCode = cc[i]) != 0) { // Simulate key down and up... GodotLib.key(0, keyCode, true); GodotLib.key(0, keyCode, false); } } } }); return true; }
@Override public boolean dispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); // Ignore volume keys so they're handled by Android if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { return false; } return super.dispatchKeyEvent(event); }
// 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; }
@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); }
@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; }
@Override public boolean dispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); // Ignore certain special keys so they're handled by Android if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_CAMERA || keyCode == 168 || /* API 11: KeyEvent.KEYCODE_ZOOM_IN */ keyCode == 169 /* API 11: KeyEvent.KEYCODE_ZOOM_OUT */) { return false; } return super.dispatchKeyEvent(event); }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: return super.onKeyDown(keyCode, event); default: break; } handleKeyDown(host, keyCode, event.getUnicodeChar()); return true; }
@Override public boolean onKeyPreIme(int keyCode, KeyEvent event) { // As seen on StackOverflow: http://stackoverflow.com/questions/7634346/keyboard-hide-event // FIXME: Discussion at http://bugzilla.libsdl.org/show_bug.cgi?id=1639 // FIXME: This is not a 100% effective solution to the problem of detecting if the keyboard is // showing or not // FIXME: A more effective solution would be to change our Layout from AbsoluteLayout to // Relative or Linear // FIXME: And determine the keyboard presence doing this: // http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android // FIXME: An even more effective way would be if Android provided this out of the box, but where // would the fun be in that :) if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { if (SDLActivity.mTextEdit != null && SDLActivity.mTextEdit.getVisibility() == View.VISIBLE) { SDLActivity.onNativeKeyboardFocusLost(); } } return super.onKeyPreIme(keyCode, event); }
public boolean onKeyDown(int KeyCode, KeyEvent event) { super.onKeyDown(KeyCode, event); if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (KeyCode) { case KeyEvent.KEYCODE_DPAD_LEFT: x -= 15; invalidate(); return true; case KeyEvent.KEYCODE_DPAD_RIGHT: x += 15; invalidate(); return true; case KeyEvent.KEYCODE_DPAD_UP: y -= 15; invalidate(); return true; case KeyEvent.KEYCODE_DPAD_DOWN: y += 15; invalidate(); return true; } } return false; }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { GodotLib.key(event.getUnicodeChar(0), true); return super.onKeyDown(keyCode, event); };
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { handleKeyUp(host, keyCode, event.getUnicodeChar()); return true; }