Skip to content

Commit 863b7c6

Browse files
committed
#1982 feat: text action does not need Key Mapper input method on Android 13+
1 parent da0b7db commit 863b7c6

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- [#1961](https://github.com/keymapperorg/KeyMapper/issues/1961) Disabling setup assistant shows a notification asking for pairing code immediately.
1919
- [#1983](https://github.com/keymapperorg/KeyMapper/issues/1983) Inputting a modifier key and another key as actions through Expert mode applies the correct key character map.
2020
- [#1990](https://github.com/keymapperorg/KeyMapper/issues/1990) Passthrough the device id of the trigger to the key event action if one is not manually specified
21+
- [#1982](https://github.com/keymapperorg/KeyMapper/issues/1982) Text action does not need Key Mapper input method on Android 13+.
2122
- Bugs with expert mode auto starting time.
2223

2324
## [4.0.0 Beta 6](https://github.com/sds100/KeyMapper/releases/tag/v4.0.0-beta.06)

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ fun ActionData.canBeHeldDown(): Boolean = when (this) {
10601060

10611061
fun ActionData.canUseImeToPerform(): Boolean = when (this) {
10621062
is ActionData.InputKeyEvent -> true
1063-
is ActionData.Text -> true
1063+
is ActionData.Text -> Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU
10641064
else -> false
10651065
}
10661066

base/src/main/java/io/github/sds100/keymapper/base/actions/PerformActionsUseCase.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,11 @@ class PerformActionsUseCaseImpl @AssistedInject constructor(
375375
}
376376

377377
is ActionData.Text -> {
378-
keyMapperImeMessenger.inputText(action.text)
378+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
379+
service.injectText(action.text)
380+
} else {
381+
keyMapperImeMessenger.inputText(action.text)
382+
}
379383
result = Success(Unit)
380384
}
381385

base/src/main/java/io/github/sds100/keymapper/base/system/accessibility/BaseAccessibilityService.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,4 +560,13 @@ abstract class BaseAccessibilityService :
560560

561561
return imeWindow != null && imeWindow.root?.isVisibleToUser == true
562562
}
563+
564+
override fun injectText(text: String) {
565+
inputMethod?.currentInputConnection?.commitText(
566+
text,
567+
// 1 puts the cursor after the inserted text.
568+
1,
569+
null,
570+
)
571+
}
563572
}

base/src/main/java/io/github/sds100/keymapper/base/system/accessibility/IAccessibilityService.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.sds100.keymapper.base.system.accessibility
22

3+
import android.os.Build
4+
import androidx.annotation.RequiresApi
35
import io.github.sds100.keymapper.base.system.inputmethod.SwitchImeInterface
46
import io.github.sds100.keymapper.common.utils.InputEventAction
57
import io.github.sds100.keymapper.common.utils.KMResult
@@ -61,4 +63,7 @@ interface IAccessibilityService : SwitchImeInterface {
6163
val isInputMethodVisible: Flow<Boolean>
6264

6365
fun findFocussedNode(focus: Int): AccessibilityNodeModel?
66+
67+
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
68+
fun injectText(text: String)
6469
}

0 commit comments

Comments
 (0)