Skip to content

Commit bf09b42

Browse files
committed
fix: wait for input events from Shizuku to processed by the application before sending the next one
1 parent bab9c86 commit bf09b42

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

app/src/main/java/io/github/sds100/keymapper/shizuku/ShizukuInputEventInjector.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import timber.log.Timber
1616
class ShizukuInputEventInjector : InputEventInjector {
1717

1818
companion object {
19-
private const val INJECT_INPUT_EVENT_MODE_ASYNC = 0
19+
// private const val INJECT_INPUT_EVENT_MODE_ASYNC = 0
20+
21+
private const val INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH = 2
2022
}
2123

2224
private val iInputManager: IInputManager by lazy {
@@ -46,12 +48,15 @@ class ShizukuInputEventInjector : InputEventInjector {
4648
model.scanCode,
4749
)
4850

49-
iInputManager.injectInputEvent(keyEvent, INJECT_INPUT_EVENT_MODE_ASYNC)
51+
// MUST wait for the application to finish processing the event before sending the next one.
52+
// Otherwise, rapidly repeating input events will go in a big queue and all inputs
53+
// into the application will be delayed or overloaded.
54+
iInputManager.injectInputEvent(keyEvent, INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH)
5055

5156
if (model.inputType == InputEventType.DOWN_UP) {
5257
val upEvent = KeyEvent.changeAction(keyEvent, KeyEvent.ACTION_UP)
5358

54-
iInputManager.injectInputEvent(upEvent, INJECT_INPUT_EVENT_MODE_ASYNC)
59+
iInputManager.injectInputEvent(upEvent, INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH)
5560
}
5661
}
5762
}

0 commit comments

Comments
 (0)