diff --git a/app/src/main/java/com/osfans/trime/data/AppPrefs.kt b/app/src/main/java/com/osfans/trime/data/AppPrefs.kt index 5e3c601ae7..5ca530effc 100644 --- a/app/src/main/java/com/osfans/trime/data/AppPrefs.kt +++ b/app/src/main/java/com/osfans/trime/data/AppPrefs.kt @@ -183,6 +183,9 @@ class AppPrefs( const val HOOK_CTRL_CV = "keyboard__hook_ctrl_cv" const val HOOK_CTRL_LR = "keyboard__hook_ctrl_lr" const val HOOK_CTRL_ZY = "keyboard__hook_ctrl_zy" + const val HOOK_SHIFT_SPACE = "keyboard__hook_shift_space" + const val HOOK_SHIFT_NUM = "keyboard__hook_shift_num" + const val HOOK_SHIFT_SYMBOL = "keyboard__hook_shift_symbol" const val SOUND_ENABLED = "keyboard__key_sound" const val SOUND_VOLUME = "keyboard__key_sound_volume" @@ -252,6 +255,15 @@ class AppPrefs( var hookCtrlZY: Boolean = false get() = prefs.getPref(HOOK_CTRL_ZY, false) private set + var hookShiftSpace: Boolean = false + get() = prefs.getPref(HOOK_SHIFT_SPACE, false) + private set + var hookShiftNum: Boolean = false + get() = prefs.getPref(HOOK_SHIFT_NUM, false) + private set + var hookShiftSymbol: Boolean = false + get() = prefs.getPref(HOOK_SHIFT_SYMBOL, false) + private set var soundEnabled: Boolean = false get() = prefs.getPref(SOUND_ENABLED, false) diff --git a/app/src/main/java/com/osfans/trime/ime/core/Trime.java b/app/src/main/java/com/osfans/trime/ime/core/Trime.java index 500c4e60af..a491c258dc 100644 --- a/app/src/main/java/com/osfans/trime/ime/core/Trime.java +++ b/app/src/main/java/com/osfans/trime/ime/core/Trime.java @@ -1087,7 +1087,7 @@ public boolean shareText() { private boolean hookKeyboard(int code, int mask) { // 編輯操作 final @Nullable InputConnection ic = getCurrentInputConnection(); if (ic == null) return false; - if (Event.hasModifier(mask, KeyEvent.META_CTRL_ON)) { + if (mask == KeyEvent.META_CTRL_ON) { if (VERSION.SDK_INT >= VERSION_CODES.M) { if (getPrefs().getKeyboard().getHookCtrlZY()) { diff --git a/app/src/main/java/com/osfans/trime/ime/keyboard/Keyboard.java b/app/src/main/java/com/osfans/trime/ime/keyboard/Keyboard.java index b25cba4497..e2e3a762d4 100644 --- a/app/src/main/java/com/osfans/trime/ime/keyboard/Keyboard.java +++ b/app/src/main/java/com/osfans/trime/ime/keyboard/Keyboard.java @@ -642,6 +642,12 @@ public boolean setMetaOn(boolean on, boolean keyDown) { // return setModifier(KeyEvent.META_FUNCTION_ON, on || keyDown); // } + public boolean isOnlyShiftOn() { + if (mShiftKey != null && mShiftKey.isOn() && mModifierState == KeyEvent.META_SHIFT_ON) + return true; + return false; + } + public boolean resetShifted() { if (mShiftKey != null && !mShiftKey.isOn()) return setModifier(KeyEvent.META_SHIFT_ON, false); return false; diff --git a/app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardView.java b/app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardView.java index 6020b46fd9..880bffebd4 100644 --- a/app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardView.java +++ b/app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardView.java @@ -1089,7 +1089,7 @@ private void detectAndSendKey(int index, int x, int y, long eventTime, KeyEventT // TextEntryState.keyPressedAt(key, x, y); final int[] codes = new int[MAX_NEARBY_KEYS]; Arrays.fill(codes, NOT_A_KEY); - getKeyIndices(x, y, codes); + // getKeyIndices(x, y, codes); // 这里实际上并没有生效 Timber.d("\t\tdetectAndSendKey()\tonEvent, code=%d, key.getEvent", code); // 可以在这里把 mKeyboard.getModifer() 获取的修饰键状态写入event里 mKeyboardActionListener.onEvent(key.getEvent(type.ordinal())); diff --git a/app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt b/app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt index d0249fc8d1..d37562eb18 100644 --- a/app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt +++ b/app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt @@ -396,7 +396,26 @@ class TextInputManager private constructor() : } KeyEvent.KEYCODE_PROG_RED -> trime.showColorDialog() // Color schemes KeyEvent.KEYCODE_MENU -> trime.showOptionsDialog() - else -> onKey(event.code, event.mask or trime.keyboardSwitcher.currentKeyboard.modifer) + else -> { + if (event.mask == 0 && trime.keyboardSwitcher.currentKeyboard.isOnlyShiftOn) { + if (event.code == KeyEvent.KEYCODE_SPACE && prefs.keyboard.hookShiftSpace) { + onKey(event.code, 0) + return + } else if (event.code >= KeyEvent.KEYCODE_0 && event.code <= KeyEvent.KEYCODE_9 && prefs.keyboard.hookShiftNum) { + onKey(event.code, 0) + return + } else if (prefs.keyboard.hookShiftSymbol) { + if (event.code >= KeyEvent.KEYCODE_GRAVE && event.code <= KeyEvent.KEYCODE_SLASH || + event.code == KeyEvent.KEYCODE_COMMA || + event.code == KeyEvent.KEYCODE_PERIOD + ) { + onKey(event.code, 0) + return + } + } + } + onKey(event.code, event.mask or trime.keyboardSwitcher.currentKeyboard.modifer) + } } } diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 7519272e3c..471bb55851 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -206,6 +206,9 @@ 每页显示候选词数量 已复制 已删除 + 点击空格时,忽略Shift的锁定状态 + 点击0-9时,忽略Shift的锁定状态 + 点击符号键时,忽略Shift的锁定状态 不超出候选栏 接近于候选栏 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 687222c9d1..ebedcfad60 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -207,6 +207,9 @@ 每頁顯示候選詞數量 已複製 已刪除 + 點擊空格時,忽略Shift的鎖定狀態 + 點擊0-9時,忽略Shift的鎖定狀態 + 點擊符號鍵時,忽略Shift的鎖定狀態 不超出候選欄 接近於候選欄 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eb2c84780e..0db50594bf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -209,6 +209,9 @@ Candidate item count for each page Copied to clipboard! Deleted + Ignore Shift locked for Space + Ignore Shift locked for 0-9 + Ignore Shift locked for Symbol keys Less than candidate close to candidate diff --git a/app/src/main/res/xml/keyboard_preference.xml b/app/src/main/res/xml/keyboard_preference.xml index 95e1af6dd7..a939efb495 100644 --- a/app/src/main/res/xml/keyboard_preference.xml +++ b/app/src/main/res/xml/keyboard_preference.xml @@ -127,6 +127,21 @@ android:title="@string/keyboard__hook_ctrl_zy" app:iconSpaceReserved="false" /> + + + + + +