Home > Blockchain >  How to simulate typing with char-by-char delay using InputConnection?
How to simulate typing with char-by-char delay using InputConnection?

Time:01-23

I need to simulate typing text with char-by-char delays using soft input keyboard on a WebView. I can't use enter image description here

when typing backwards with ic.commitText(char.toString(), 0) it types fully:

enter image description here

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))
}
  • Related