fix: input mobile -> Android (#9767)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-11-08 12:11:56 +08:00 committed by GitHub
parent 0f070b0108
commit 7978e0301d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 11 deletions

View File

@ -280,20 +280,20 @@ class InputService : AccessibilityService() {
var textToCommit: String? = null var textToCommit: String? = null
if (keyboardMode == KeyboardMode.Legacy) { // [down] indicates the key's state(down or up).
if (keyEvent.hasChr() && keyEvent.getDown()) { // [press] indicates a click event(down and up).
// https://github.com/rustdesk/rustdesk/blob/3a7594755341f023f56fa4b6a43b60d6b47df88d/flutter/lib/models/input_model.dart#L688
if (keyEvent.hasSeq()) {
textToCommit = keyEvent.getSeq()
} else if (keyboardMode == KeyboardMode.Legacy) {
if (keyEvent.hasChr() && (keyEvent.getDown() || keyEvent.getPress())) {
val chr = keyEvent.getChr() val chr = keyEvent.getChr()
if (chr != null) { if (chr != null) {
textToCommit = String(Character.toChars(chr)) textToCommit = String(Character.toChars(chr))
} }
} }
} else if (keyboardMode == KeyboardMode.Translate) { } else if (keyboardMode == KeyboardMode.Translate) {
if (keyEvent.hasSeq() && keyEvent.getDown()) { } else {
val seq = keyEvent.getSeq()
if (seq != null) {
textToCommit = seq
}
}
} }
Log.d(logTag, "onKeyEvent $keyEvent textToCommit:$textToCommit") Log.d(logTag, "onKeyEvent $keyEvent textToCommit:$textToCommit")
@ -320,6 +320,10 @@ class InputService : AccessibilityService() {
} else { } else {
ke?.let { event -> ke?.let { event ->
inputConnection.sendKeyEvent(event) inputConnection.sendKeyEvent(event)
if (keyEvent.getPress()) {
val actionUpEvent = KeyEventAndroid(KeyEventAndroid.ACTION_UP, event.keyCode)
inputConnection.sendKeyEvent(actionUpEvent)
}
} }
} }
} }
@ -333,6 +337,10 @@ class InputService : AccessibilityService() {
for (item in possibleNodes) { for (item in possibleNodes) {
val success = trySendKeyEvent(event, item, textToCommit) val success = trySendKeyEvent(event, item, textToCommit)
if (success) { if (success) {
if (keyEvent.getPress()) {
val actionUpEvent = KeyEventAndroid(KeyEventAndroid.ACTION_UP, event.keyCode)
trySendKeyEvent(actionUpEvent, item, textToCommit)
}
break break
} }
} }

View File

@ -31,14 +31,12 @@ object KeyEventConverter {
} }
var action = 0 var action = 0
if (keyEventProto.getDown()) { if (keyEventProto.getDown() || keyEventProto.getPress()) {
action = KeyEvent.ACTION_DOWN action = KeyEvent.ACTION_DOWN
} else { } else {
action = KeyEvent.ACTION_UP action = KeyEvent.ACTION_UP
} }
// FIXME: The last parameter is the repeat count, not modifiers ?
// https://developer.android.com/reference/android/view/KeyEvent#KeyEvent(long,%20long,%20int,%20int,%20int)
return KeyEvent(0, 0, action, chrValue, 0, modifiers) return KeyEvent(0, 0, action, chrValue, 0, modifiers)
} }

View File

@ -560,6 +560,14 @@ class _RemotePageState extends State<RemotePage> with WidgetsBindingObserver {
controller: _textController, controller: _textController,
// trick way to make backspace work always // trick way to make backspace work always
keyboardType: TextInputType.multiline, keyboardType: TextInputType.multiline,
// `onChanged` may be called depending on the input method if this widget is wrapped in
// `Focus(onKeyEvent: ..., child: ...)`
// For `Backspace` button in the soft keyboard:
// en/fr input method:
// 1. The button will not trigger `onKeyEvent` if the text field is not empty.
// 2. The button will trigger `onKeyEvent` if the text field is empty.
// ko/zh/ja input method: the button will trigger `onKeyEvent`
// and the event will not popup if `KeyEventResult.handled` is returned.
onChanged: handleSoftKeyboardInput, onChanged: handleSoftKeyboardInput,
), ),
), ),