An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.
Rust androidanydeskdartflatpakflutterflutter-appsioslinuxmacosp2prdpremote-controlremote-desktoprustrust-langteamviewervncwaylandwindows
feat: use current input method to send key
mcfans9a903a1ca31a
diff --git a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.ktindex 8e0582d17..dae86c3db 100644--- a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt+++ b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt@@ -17,6 +17,8 @@ import android.util.Logimport android.widget.EditTextimport android.view.accessibility.AccessibilityEventimport android.view.accessibility.AccessibilityNodeInfo+import android.accessibilityservice.AccessibilityServiceInfo+import android.accessibilityservice.AccessibilityServiceInfo.FLAG_INPUT_METHOD_EDITORimport androidx.annotation.RequiresApiimport java.util.*import kotlin.math.abs@@ -65,8 +67,6 @@ class InputService : AccessibilityService() {private var isWheelActionsPolling = falseprivate var isWaitingLongPress = false- private var fakeEditTextForTextStateCalculation: EditText? = null-@RequiresApi(Build.VERSION_CODES.N)fun onMouseInput(mask: Int, _x: Int, _y: Int) {val x = max(0, _x)@@ -264,85 +264,24 @@ class InputService : AccessibilityService() {@RequiresApi(Build.VERSION_CODES.N)fun onKeyEvent(data: ByteArray) {val keyEvent = KeyEvent.parseFrom(data);- val handler = Handler(Looper.getMainLooper())- handler.post {- findFocus(AccessibilityNodeInfo.FOCUS_INPUT)?.let { node ->- val text = node.getText()- val isShowingHint = node.isShowingHintText()-- var textSelectionStart = node.getTextSelectionStart()- var textSelectionEnd = node.getTextSelectionEnd()-- if (text != null) {- if (textSelectionStart > text.length) {- textSelectionStart = text.length- }- if (textSelectionEnd > text.length) {- textSelectionEnd = text.length- }- if (textSelectionStart > textSelectionEnd) {- textSelectionStart = textSelectionEnd- }- }-- if (keyEvent.hasSeq()) {- val seq = keyEvent.getSeq()-- var newText = ""-- if ((textSelectionStart == -1) || (textSelectionEnd == -1)) {- newText = seq- } else {- newText = text.let {- it.substring(0, textSelectionStart) + seq + it.substring(textSelectionStart)- }- }-- val arguments = Bundle()- arguments.putCharSequence(- AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE,- newText- )- node.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments)-- } else {- KeyEventConverter.toAndroidKeyEvent(keyEvent).let { event ->- Log.d(logTag, "event $event text $text start $textSelectionStart end $textSelectionEnd")- if (isShowingHint) {- this.fakeEditTextForTextStateCalculation?.setText(null)- } else {- this.fakeEditTextForTextStateCalculation?.setText(text)- }- if (textSelectionStart != -1 && textSelectionEnd != -1) {- this.fakeEditTextForTextStateCalculation?.setSelection(- textSelectionStart,- textSelectionEnd- )- }- this.fakeEditTextForTextStateCalculation?.dispatchKeyEvent(event)-- this.fakeEditTextForTextStateCalculation?.getText()?.let { newText ->- val arguments = Bundle()- arguments.putCharSequence(- AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE,- newText.toString()- )- node.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments)- }- }+ getInputMethod()?.let { inputMethod ->+ inputMethod.getCurrentInputConnection()?.let { inputConnection ->+ KeyEventConverter.toAndroidKeyEvent(keyEvent).let { event ->+ inputConnection.sendKeyEvent(event)}}}}- override fun onAccessibilityEvent(event: AccessibilityEvent) {- }+ override fun onAccessibilityEvent(event: AccessibilityEvent) {}override fun onServiceConnected() {super.onServiceConnected()ctx = this- fakeEditTextForTextStateCalculation = EditText(this)+ val info = AccessibilityServiceInfo()+ info.flags = FLAG_INPUT_METHOD_EDITOR+ setServiceInfo(info)Log.d(logTag, "onServiceConnected!")}diff --git a/flutter/android/app/src/main/res/xml/accessibility_service_config.xml b/flutter/android/app/src/main/res/xml/accessibility_service_config.xmlindex 90b57cd4e..fa9407128 100644--- a/flutter/android/app/src/main/res/xml/accessibility_service_config.xml+++ b/flutter/android/app/src/main/res/xml/accessibility_service_config.xml@@ -1,6 +1,5 @@<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"android:accessibilityEventTypes="typeWindowsChanged"- android:canRetrieveWindowContent="true"android:accessibilityFlags="flagDefault"android:notificationTimeout="50"android:description="@string/accessibility_service_description"