Status Update
Comments
ra...@google.com <ra...@google.com>
ra...@google.com <ra...@google.com> #2
We have shared this with our product and engineering team and will update this issue with more information as it becomes available.
en...@google.com <en...@google.com> #3
Sadly, I can't enter any character I wish, such as of other languages. I think it supports only ascii...
adb is fine:
~$ adb shell echo '1박 2일'
1박 2일
~$ adb shell echo '1박 2일'| xxd
00000000: 31eb b095 2032 ec9d bc0a 1... 2....
~$
but it does look like the 'input' command might have issues:
~$ adb shell input keyboard text '1박 2일'
Exception occurred while executing 'keyboard':
java.lang.NullPointerException: Attempt to get length of null array
at com.android.server.input.InputShellCommand.sendText(InputShellCommand.java:318)
at com.android.server.input.InputShellCommand.runText(InputShellCommand.java:290)
at com.android.server.input.InputShellCommand.onCommand(InputShellCommand.java:231)
at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
at android.os.ShellCommand.exec(ShellCommand.java:38)
at com.android.server.input.InputManagerService.onShellCommand(InputManagerService.java:3432)
at android.os.Binder.shellCommand(Binder.java:968)
at android.os.Binder.onTransact(Binder.java:849)
at android.hardware.input.IInputManager$Stub.onTransact(IInputManager.java:981)
at android.os.Binder.execTransactInternal(Binder.java:1205)
at android.os.Binder.execTransact(Binder.java:1163)
~$
what's the code?
final char[] chars = buff.toString().toCharArray();
final KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
final KeyEvent[] events = kcm.getEvents(chars);
for (int i = 0; i < events.length; i++) {
KeyEvent e = events[i];
if (source != e.getSource()) {
e.setSource(source);
}
e.setDisplayId(displayId);
injectKeyEvent(e);
}
okay, so maybe you have to have the right virtual keyboard in use?
nope ... changing to the korean keyboard doesn't fix my korean example above.
over to lzye who seems to have touched this last, and might know whether this is a bug/regression/unfortunate unfixable limitation.
lb...@gmail.com <lb...@gmail.com> #4
If anyone knows about AccessibilityService, please answer me about this possible workaround of this matter, to dispatch unicode keys through it:
mi...@google.com <mi...@google.com>
pr...@google.com <pr...@google.com>
lb...@gmail.com <lb...@gmail.com> #5
It's very much possible, and it can help everyone, including of course people with disabilities (being able to type using alternative methods, and not just touch, for example).
Why close without explanation...
lb...@gmail.com <lb...@gmail.com> #6
lb...@gmail.com <lb...@gmail.com> #7
There is also no "setDisplayId", and no "injectKeyEvent".
Where do you see such things?
See attached project.
ar...@google.com <ar...@google.com> #8
They are two different concepts:
The adb shell input text abc
: means it would send mulitple key events of a
b
c
within a command,
so it first seperate the input string to each character then generate key events to inject.
And the expectation of this request is to deliver the content text to an edit text or some focused view.
It could ignore the framework process.
For example:
probadly use UiAutomation to find the focused view and call its setText
if any.
lb...@gmail.com <lb...@gmail.com> #9
All should be possible: dispatching a single character or multiple ones together, to focused View or in general (like on a physical keyboard).
Are you saying something is already possible using accessibility? But then why was it denied when I requested it? Why only very few keys can be used globally?
I just want to be able to dispatch all kinds of keys, using both adb and accessibility.
It can help everyone, not just people with disabilities.
Mirroring is only one of the possible things that this can enhance.
For people with disabilities, it can help in case touches on the screen isn't always possible, for example. Typing using alternative methods can be achieved this way (adb and accessibility).
And of course, for testing apps and running macros, it can help for automatic testing, whether there is a PC nearby (using adb) or not (using accessibility).
to...@unity3d.com <to...@unity3d.com> #10
Hey,
any news on this one, we would also like to be able to send UTF8 characters via adb shell input text ?
Thank you
en...@google.com <en...@google.com>
mi...@google.com <mi...@google.com>
jo...@google.com <jo...@google.com>
mi...@google.com <mi...@google.com> #11
might know whether this is a bug/regression/unfortunate unfixable limitation.
This a limitation; perhaps not an unfixable one but it does require some design (and some concrete use cases to understand if this is even the right tool for the job). The input
command injects hardware keys, not raw text -- this means that we need to map the given text back to hardware keys in order to inject it. This design has several problems when it comes to unicode:
-
Switching the keyboard layout is done per device and there's no way to do so for the virtual keyboard today. If the tool did switch the layout to be able to inject unicode, the virtual keyboard is a global device so the layout would be changed for all clients, which isn't really safe (though unclear to me how much of a problem that is).
-
Even if you can set the layout, our list of languages supported by physical keyboards is relatively small and wouldn't cover a large number of languages. We also don't require devices to support the languages we do have layouts for today, so it wouldn't be guaranteed to work across the ecosystem (unless we added policy to require language support).
-
Even if we supported all languages, you still can't input a huge amount of the unicode range -- not all text can be directly mapped to physical key presses. Some languages require IME interactions to compose / transliterate. Some codepoints are modifiers that need to be combined with other characters. No keys will ever really map to these.
I kind of think this most people just care about the text and not the physical key input, so maybe this should just go through the IMF framework instead. This would, unfortunately, break anyone using the input
command to test hardware key interactions however. The other option would be to introduce some way on Android to inject arbitrary unicode code points (e.g. AltGr+codepoint) and then inject those keys, which is a bit roundabout. If people actually want to test physical keyboard input though, then we need to think about how to actually configure the device (e.g. do we need clients to tell us the layout? do we need to require OEMs ship support for all layouts in AOSP? etc).
Anyways. I do think we need some concrete use cases here so we can design the right thing and give it the right priority.
sp...@google.com <sp...@google.com> #12
+1 for a mechanism to inject arbitrary code points. Ideally, not just through ADB, but also programmatically. Device mirroring in Studio would greatly benefit from this. See, for example,
jo...@google.com <jo...@google.com> #13
All major platforms support Unicode insertion via keyboard shortcuts, so to me it looks like a good feature to add. That said, I never liked the AltGr+code Windows Unicode entry (or Mac's equivalent) for a couple of reasons: it's decimal, and it actually collides with legitimate mappings. Instead, I believe the Linux shortcut (Ctrl+Shift+U+hex code) does not have any shortcoming.
After Android has this mechanism, it would be quite straightforward to modify KeyCharacterMap#getEvents
to generate events that fall back to the unicode entry when the built-in keyboard KCM doesn't define the target character. Because this mechanism is not in place today, the text entry using this method is not reliable, which is why the documentation suggests an alternative (ACTION_MULTIPLE) that became deprecated some years ago.
While this solution would add Unicode support to adb shell input text
, no modification would be needed on InputShellCommand
.
su...@google.com <su...@google.com> #14
It's actually pretty straightforward to support it in Gboard. We can implement a hidden feature in Gboard to intercept key event sequences with a special format, e.g. ctrl+shift+u+hex code, and output the corresponding Unicode text to the app.
Then no change needs to be done in Android system, and we can support it on all Android versions as long as it has the latest Gboard as the default IME.
WDYT?
lb...@gmail.com <lb...@gmail.com> #15
1. Old Android versions on real devices: use the workaround of a keyboard app as you wrote. I hope that Gboard on this newest version would be able to be installed on as many Android versions as possible, including old Android devices and emulators of all kinds.
2. emulators : implement it right inside, as you have control over what's sent to them
3. Android 14 and above on any device/emulator : this is the time to add it for real. No need for any workaround. Should support adding a single character and a whole string too.
Keyboard app shouldn't be responsible of input from adb commands. This is a workaround till it's implemented properly.
There are multiple reasons for why it's a workaround, and I'm sure you can think about why.
One reason is that if we want to type a message in adb, it would require us to mimic every character, one after another, instead of :
adb shell "input keyboard text 'This goes to Android device'"
Sure you could change the adb to mimic it for us on old Android versions, but the best thing is not to rely on an app being set as default keyboard.
There are even cases that users can put text without the keyboard app, or when Gboard isn't the default, or when you test a keyboard app, let alone on accessibility scenarios.
And of course the scenario that I reached : mirroring the device (either via ScrCpy or Android Studio or any other mirroring solution).
lb...@gmail.com <lb...@gmail.com> #16
Also, you want 4 keys to be pressed at the same time, and some of them are quite far from one another. I will need 3 hands instead of 2...
jo...@google.com <jo...@google.com> #17
Ctrl and Shift are modifier keys; using them as a shortcut would break any other usage; for instance Ctrl+Shift+Arrows modifies the text selection.
What I was proposing is the same feature as Linux: Ctrl+Shift+U enters Unicode compose; releasing Ctrl or Shift ends it. This would require holding Ctrl+Shift with one hand and typing the code with the other, which seems like adequate UX to me.
Android already had the ability to pass strings over KeyEvent (ACTION_MULTIPLE), but seems like it didn't work out and was deprecated about 5 years ago. I don't know the reasons why, but probably deserved it, and the APi is more elegant without it IMHO.
I don't think this should be done at Gboard level; I'll add a technician proposal later today about what I believe to be the best way to implement it.
lb...@gmail.com <lb...@gmail.com> #18
Each OS has its own shortcuts of how to write unicode manually. Please don't change this.
You can have for Android its own solution, just please think about it well and add it for the new Android version (Android 14) and somehow add for old Android versions too using any workaround you can think of.
What happens in "unicode compse" mode? Does the UI change? Do you want the UI to change on Android OS itself?
Also, are you saying it's impossible right now to use adb to send a combination of keys ? If so, I think you should bring it back and fix it on the way, at least for Android 14.
About Gboard, I thought you meant it would be a way to offer the feature on old Android versions
jo...@google.com <jo...@google.com> #19
Support for older versions of Android could be done via Gboard indeed; however, I don't think it possible to retrofit the adb shell input text
command to support the conversion from Unicode text to events that generate it; instead, we would need to generate the key events that would produce that output. Producing multiple key combinations is possible with the current input
shell command.
Android does not have at the moment a way to write Unicode manually, which is why I'm proposing the "Unicode compose mode". Yes, this would be a change in Android itself, and it would take a while toac
@su...@google.com I think the best course of action here would be to implement this on Gboard, and then just disable it if we decide to implement it at framework level. What do you think? Should I assigned this request to you?
jo...@google.com <jo...@google.com> #20
*Android does not have at the moment a way to write Unicode manually, which is why I'm proposing the "Unicode compose mode". Yes, this would be a change in Android itself, and it would take a while to actually become available to devices.
jo...@google.com <jo...@google.com> #21
From API level 35 we could implement the Unicode compose mode in core/java/android/text/method/QwertyKeyListener
; we even have an inactive path there from a previous implementation:
cn...@gmail.com <cn...@gmail.com> #22
jo...@google.com <jo...@google.com> #23
The same is true for any of the current mechanism we have at the moment, like accent composition; even if this feature would not initially work on some IMEs, it currently does not work in any, so it's a improvement.
lb...@gmail.com <lb...@gmail.com> #24
For example, onKeyPressed of Activity should be able to handle a key that is in non-English, even if a keyboard app isn't shown yet.
Why do you think there is no option to handle ` adb shell input text` ? The command could first check the existence&version of the keyboard app, and then if it matches, send the commands that the keyboard app knows of.
Please offer `adb shell input text` support, at least on the new Android version (14).
@20 That's cool. You could have the UI show a grid of the digits, and in each cell it would show the digit and the output of the character if it's done, and even extras if you wish.
You could also offer an API to reach this UI, for both the keyboard app and for the current foreground app.
There should be a default UI to handle it, and if the keyboard app wishes, it could also replace it and offer its own unique features for it.
@21 You skipped an API version. We are now on API 33.
Android 14 is the one that's going to be published soon, which is API 34.
@23 I don't understand, but please also offer the putting of characters of all kinds into AccessibilityService too. Currently I think it's very limited.
jo...@google.com <jo...@google.com> #25
API 34 is already finalised, so it's not possible to add more changes.
lb...@gmail.com <lb...@gmail.com> #26
Does it mean that there won't be even changes to fix things? For example still not being able to get current wallpaper unless MANAGE_EXTERNAL_STORAGE permission is granted? I was hoping that the new READ_MEDIA_IMAGES would be used ...
:(
jo...@google.com <jo...@google.com> #27
I'm afraid I have no information on that, but I'm talking about the API, not the build.
jo...@google.com <jo...@google.com>
su...@google.com <su...@google.com> #28
Just filed
Let's leave this bug for the ideal implementation in Android framework.
lblb636 it'd be very helpful if you could provide some actual use cases for this feature request.
sp...@google.com <sp...@google.com> #29
See
lb...@gmail.com <lb...@gmail.com> #30
1. Mirroring apps , such as ScrCpy and Android Studio
2. Batch files
3. Emulators don't support even normal keyboards unicode being used... and that's not just the emulator by Google. All of them...
4. Using workarounds, this could offer the same feature for previous Android versions.
5. After adding this to accessibilityService, this could help with accessibility-related apps and enhancement/tools apps.
6. Manual and automated testing
Description
Example is this one, which lets us enter characters as a string:
adb shell "input keyboard text 'This goes to Android device'"
Sadly, I can't enter any character I wish, such as of other languages. I think it supports only ascii...