Does “adb shell input text” simulate software keyboard input?

允我心安 提交于 2019-12-08 15:55:20

问题


adb shell input text "sometext"

OR

adb shell input keyevent eventid

do these simulate actual input from a virtual/ hardware keyboard respectively ?

I did not find any documentation for these commands on developer.android.com/

Is there any trusted documentation for these commands?


回答1:


adb shell input help produces (after a long list of input devices):

The commands and default sources are:
  text <string> (Default: touchscreen)
  keyevent [--longpress] <key code number or name> ... (Default: keyboard)
  tap <x> <y> (Default: touchscreen)
  swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
  press (Default: trackball)
  roll <dx> <dy> (Default: trackball)

So it seems "text" is indeed for virtual (Default: touchscreen) and keyevent for physical (Default: keyboard).

You can override the text input device - adb shell input keyboard text "foo" works just fine. You can't send raw keycodes from the screen though.




回答2:


Related to

adb shell input text "some\ text"

I only find the source code: E. g. for Android 8.1 here.

The method private void sendText(int source, String text) { is relevant for the encoding.

And searching for KeyCharacterMap.VIRTUAL_KEYBOARD that is used in previous method I found a description here for heading "Virtual Key Character Map File".

From that info I looked into an old SM-G900F. I found under /system/usr/keychars/Virtual.kcm. Inside of that file it maps the key events to the most common characters (mostly only ASCII).

So to your question:

do these simulate actual input from a virtual/ hardware keyboard respectively ?

Yes, the code takes the text and tries to map it back via the KeyCharacterMap.VIRTUAL_KEYBOARD to key events and sends them.

In my experience all unknown characters lead to a cancellation of the whole text. And you have to escape some characters - sometimes space with %s, or with '\ ', other special characters like & have to be escaped too.

And on some devices I experienced that a long text (ca. 200 characters) written with adb shell input text "<longText>" was partly lost - even the bigger part at the end! It looked to me depending on the manufacturer.




回答3:


There is a good description available for adb shell input * commands, just type

adb shell input help

For adb shell keyevent commands, different keycodes are available.




回答4:


"adb shell input keyevent eventid" for sure will not simulate real keyevent as the device id == 0.

what about "adb shell input text "sometext"" it is anyway not from pysical ... so I guess it will do is as clikcing on softkeyboard ?



来源:https://stackoverflow.com/questions/25782199/does-adb-shell-input-text-simulate-software-keyboard-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!