I need to simulate typing text with char-by-char delays using soft input keyboard on a WebView. I can't use
when typing backwards with ic.commitText(char.toString(), 0)
it types fully:
The test is running on Android 12.
CodePudding user response:
InputConnection#commitText()
replaces the contents of the actual composing region. To add new characters you need to move the composing region forward (the "cursor") with InputConnection#setComposingRegion()
. Try:
for (i in text.indices) {
ic.setComposingRegion(i, i 1)
ic.commitText(text[i].toString(), 1)
delay(Random.nextLong(keyDelayStart, keyDelayEnd))
}