Thursday, 2 December 2021

Can AccessibilityService dispatch key events, including even Unicode characters?

Background

I want to try to send Unicode characters from the PC to the Android device via adb commands. Characters from various languages, for example.

The problem

Such a thing is impossible, as it supports only a basic set of characters (probably only Ascii) :

adb shell "input keyboard text 'This goes to Android device'"

Because of this, I've decided to request it to be supported, here (please consider starring).

As a workaround, I thought that maybe I could developer an app that uses AccessibilityService and it would dispatch key events as if I'm typing via the device.

Thing is, after creating the app, I can't find which function I should use to do it.

What I've found

There are multiple things I've found:

  1. onAccessibilityEvent - this is not for dispatching. It's only for getting events, which I don't think I will even need in this case.
  2. getSoftKeyboardController - a function that can help with hiding the automatically shown keyboard, but that's about it...
  3. dispatchGesture - a function that seems to be used only for dispatching touch events. It seems quite cool, but I don't see that it can handle keys.
  4. performGlobalAction - seems promising, but sadly supports a very limited set of operations (back-key, home-key, etc...).
  5. findFocus - I think I could use this and then dispatch a key event on what I get, but I'm not sure if this is a valid way to do it as I want to dispatch the event globally (plus maybe I would get null object, which means it might not be reliable). Not to mention that according to the options I see, it doesn't allow me to put the text right on the caret and that's it.

The question

Is it possible for AccessibilityService to dispatch a key event of Unicode characters, as if I type some text?

What's the best option to use for this?



from Can AccessibilityService dispatch key events, including even Unicode characters?

No comments:

Post a Comment