Skip to content

Commit eb70fe4

Browse files
fix(keyboard): filter NumLock modifier for non-numpad keys in scrcpy (#1844)
* Initial plan * Fix NumLock being sent with space/backspace in scrcpy Filter out NumLock modifier for non-numpad keys to prevent it from being incorrectly sent to Rime when using scrcpy. This fixes the issue where space key and backspace key were not working properly in scrcpy because NumLock was being sent along with them. Co-authored-by: WhiredPlanck <47623588+WhiredPlanck@users.noreply.github.com> * Add missing KeyModifier import Co-authored-by: WhiredPlanck <47623588+WhiredPlanck@users.noreply.github.com> * Use explicit bitwise operation to clear NumLock modifier Address code review feedback to use KeyModifier.Mod2.modifier explicitly with bitwise AND and inversion instead of the minus operator. Co-authored-by: WhiredPlanck <47623588+WhiredPlanck@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: WhiredPlanck <47623588+WhiredPlanck@users.noreply.github.com>
1 parent 18ae23d commit eb70fe4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import androidx.core.content.ContextCompat
3535
import androidx.core.view.inputmethod.EditorInfoCompat
3636
import androidx.core.view.updateLayoutParams
3737
import androidx.lifecycle.lifecycleScope
38+
import com.osfans.trime.core.KeyModifier
3839
import com.osfans.trime.core.KeyModifiers
3940
import com.osfans.trime.core.KeyValue
4041
import com.osfans.trime.core.RimeApi
@@ -668,7 +669,12 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
668669

669670
private fun forwardKeyEvent(event: KeyEvent): Boolean {
670671
val up = event.action == KeyEvent.ACTION_UP
671-
val modifiers = KeyModifiers.fromKeyEvent(event)
672+
var modifiers = KeyModifiers.fromKeyEvent(event)
673+
// Filter out NumLock for non-numpad keys to fix scrcpy issue
674+
// where NumLock is incorrectly sent with keys like space and backspace
675+
if (event.keyCode !in KeyEvent.KEYCODE_NUMPAD_0..KeyEvent.KEYCODE_NUMPAD_EQUALS) {
676+
modifiers = KeyModifiers(modifiers.modifiers and KeyModifier.Mod2.modifier.inv())
677+
}
672678
val charCode = event.unicodeChar
673679
if (charCode > 0 && charCode != '\t'.code && charCode != '\n'.code && charCode != ' '.code) {
674680
// drop modifier state when using combination keys to input number/symbol on some phones

0 commit comments

Comments
 (0)