@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; }
public void sendChars(CharSequence chars) { final NetworkPackage np = new NetworkPackage(MousePadPlugin.PACKAGE_TYPE_MOUSEPAD_REQUEST); np.set("key", chars.toString()); sendKeyPressPackage(np); }