l'-'l
l'-'l

Reputation: 438

Does "adb shell input text" simulate software keyboard input?

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?

Upvotes: 16

Views: 37611

Answers (5)

Maniche
Maniche

Reputation: 93

I am developing a work that evaluate the performance among different keyboards and tries to simulate real-user keyboard typing. The tool that I am using (android view client) uses input text to send text to the device. However, when using this tool to simulate text input, I observed differences in the behaviour of the keyboards, caused by the usage of this input method.

Using input text, the pointer location doesn't change and the keyboard doesn't show any keypress animations. Contrariwise, when using input tap X Y to press a key, the visual behaviour is the same as a real user taping the key. Also, the behaviour of the GBoard is different for both input methods. When using input text and then tapping a suggested word, the keyboard doesn't add a trailing space. The same doesn´t happen when using input tap. This helps to conclude that indeed there are differences between these two input methods.

Upvotes: 0

Sion C
Sion C

Reputation: 451

"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 ?

Upvotes: -1

BitLauncher
BitLauncher

Reputation: 693

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.

Upvotes: 5

Ravi Bhayani
Ravi Bhayani

Reputation: 151

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.

Upvotes: 2

SF.
SF.

Reputation: 14077

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.

Upvotes: 7

Related Questions