Sample Header Ad - 728x90

Is there any way for an app to insert text at the cursor in another app, in the currently focused input field? (With the ‘accessibility’ permission)

0 votes
0 answers
179 views
I'd like to have an app with my custom programmatic text snippets, that would insert them at the cursor in the focused text field, next to other text that I already entered. I'm using both Tasker and Automate, and both can enter text letter-by-letter, or rather keycode-by-keycode—with me translating the letters to keycodes, I guess. Neither of the two can just insert text: instead, Automate can ‘set text’, overriding all text in the field, and IIRC Tasker's docs suggest using some command via adb, that requires root permissions. I wonder: is there perhaps some way to just spill some text into the focused input, at the cursor, without affecting surrounding text? Both apps have the permission to work as accessibility-helping apps. I asked this question in one of Automate's communities, and was [directed towards the docs for ACTION_SET_TEXT](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#ACTION_SET_TEXT) , which doesn't have any options to specify the target position for the text, or to keep the text that's already there. I would vaguely hope that accessibility apps can help the user with entering text, among other things, and thus have some means to that end. There's a kind-of-a-workaround with setting the clipboard text and then pasting it, but that's rather dirty since the existing clipboard value is not preserved: I looked into getting the clipboard contents and putting them back after all is done, but this turns out to require a rooted phone again. Plus the solution is generally hacky. Maybe there's some way to get the cursor position in the text field, extract text before and after the cursor, and then use SET_TEXT? I could live with the text formatting being lost, if only that would allow me to enter snippets.
Asked by aaa (143 rep)
Nov 5, 2021, 09:44 PM
Last activity: Nov 6, 2021, 08:33 PM