diff options
| author | mirfatif <mirfatif@gmail.com> | 2020-08-06 11:31:15 +0000 |
|---|---|---|
| committer | mirfatif <mirfatif@gmail.com> | 2020-08-07 05:01:53 +0000 |
| commit | e712b7782a2b6be9ea748fec9ff5ef2604d8cc3e (patch) | |
| tree | 6fa84f4efbe14cb25a4ea92d9cf0c860369f0efc /ime/app/src/main | |
| parent | 020d841c16ab92963d2085032eeeaae9cfc3130c (diff) | |
| download | AnySoftKeyboard-e712b7782a2b6be9ea748fec9ff5ef2604d8cc3e.tar.gz AnySoftKeyboard-e712b7782a2b6be9ea748fec9ff5ef2604d8cc3e.tar.bz2 | |
Make Ctrl work with non-terminal apps too
Diffstat (limited to 'ime/app/src/main')
| -rw-r--r-- | ime/app/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/ime/app/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java b/ime/app/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java index d39a2373b..759716f5b 100644 --- a/ime/app/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java +++ b/ime/app/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java @@ -608,6 +608,24 @@ public abstract class AnySoftKeyboard extends AnySoftKeyboardColorizeNavBar { } } + // convert ASCII codes to Android KeyEvent codes + // ASCII Codes Table: https://ascii.cl + private int getKeyCode(int ascii) { + // A to Z + if (ascii >= 65 && ascii <= 90) return (KeyEvent.KEYCODE_A + ascii - 65); + // a to z + if (ascii >= 97 && ascii <= 122) return (KeyEvent.KEYCODE_A + ascii - 97); + + return 0; + } + + // send key events + private void sendKeyEvent(InputConnection ic, int action, int keyCode, int meta) { + if (ic == null) return; + long now = System.currentTimeMillis(); + ic.sendKeyEvent(new KeyEvent(now, now, action, keyCode, 0, meta)); + } + private void onNonFunctionKey( final int primaryCode, final Keyboard.Key key, @@ -667,8 +685,16 @@ public abstract class AnySoftKeyboard extends AnySoftKeyboardColorizeNavBar { default: if (isWordSeparator(primaryCode)) { handleSeparator(primaryCode); - } else { - if (mControlKeyState.isActive() && primaryCode >= 32 && primaryCode < 127) { + } else if (mControlKeyState.isActive()) { + int keyCode = getKeyCode(primaryCode); + if (Build.VERSION.SDK_INT >= 11 && keyCode != 0) { + // TextView (and hence its subclasses) can handle ^A, ^Z, ^X, ^C and ^V + // https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-10.0.0_r1/core/java/android/widget/TextView.java#11136 + // simulate physical keyboard behavior i.e. press and release a key while + // keeping Ctrl pressed + sendKeyEvent(ic, KeyEvent.ACTION_DOWN, keyCode, KeyEvent.META_CTRL_MASK); + sendKeyEvent(ic, KeyEvent.ACTION_UP, keyCode, KeyEvent.META_CTRL_MASK); + } else if (primaryCode >= 32 && primaryCode < 127) { // http://en.wikipedia.org/wiki/Control_character#How_control_characters_map_to_keyboards int controlCode = primaryCode & 31; Logger.d( @@ -684,6 +710,8 @@ public abstract class AnySoftKeyboard extends AnySoftKeyboardColorizeNavBar { } else { handleCharacter(primaryCode, key, multiTapIndex, nearByKeyCodes); } + } else { + handleCharacter(primaryCode, key, multiTapIndex, nearByKeyCodes); } break; } |
