Android “adb shell input text”是否模拟软件键盘输入?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25782199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:43:16  来源:igfitidea点击:

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

androidadbandroid-virtual-keyboard

提问by l'-'l

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/

我在 developer.android.com/ 上没有找到这些命令的任何文档

Is there any trusted documentation for these commands?

是否有这些命令的可信文档?

回答by SF.

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

adb shell input help产生(在一长串输入设备之后):

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.

您可以覆盖文本输入设备 -adb shell input keyboard text "foo"工作得很好。但是,您无法从屏幕发送原始键码。

回答by BitLauncher

Related to

相关

adb shell input text "some\ text"

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

我只找到源代码:例如 适用于此处的 Android 8.1

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

该方法 private void sendText(int source, String text) {与编码相关。

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

并搜索KeyCharacterMap.VIRTUAL_KEYBOARD在以前的方法中使用的我在这里找到了标题“虚拟键字符映射文件”的描述

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).

根据该信息,我查看了旧的 SM-G900F。我在/system/usr/keychars/Virtual.kcm. 在该文件中,它将关键事件映射到最常见的字符(主要是 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.

是的,代码获取文本并尝试通过 KeyCharacterMap.VIRTUAL_KEYBOARD 将其映射回关键事件并发送它们。

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.

根据我的经验,所有未知字符都会导致整个文本被取消。并且您必须对某些字符进行转义 -有时带有 %s 或 '\ ' 的空格,其他特殊字符(如 & 也必须进行转义)。

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.

在某些设备上,我遇到了用它编写的长文本(约 200 个字符)adb shell input text "<longText>"部分丢失的情况 - 甚至在结尾处丢失了更大的部分!在我看来,这取决于制造商。

回答by Ravi Bhayani

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

adb shell input *命令有很好的描述,只需输入

adb shell input help

For adb shell keyeventcommands, different keycodesare available.

对于adb shell keyevent命令,可以使用不同的键码

回答by Rui Rua

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 textto 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.

我正在开发一项评估不同键盘之间性能的工作,并尝试模拟真实用户的键盘输入。我正在使用的工具(android 视图客户端)使用输入文本将文本发送到设备。但是,在使用此工具模拟文本输入时,我观察到由于使用此输入法而导致键盘行为的差异。

Using input text, the pointer location doesn't change and the keyboard doesn't show any keypress animations. Contrariwise, when using input tap X Yto 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 textand 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.

使用input text,指针位置不会改变,键盘也不会显示任何按键动画。相反,当使用输入点击 XY按键时,视觉行为与真实用户点击按键相同。此外,两种输入法的 GBoard 行为也不同。使用输入文本然后点击建议的单词时,键盘不会添加尾随空格。使用input tap时不会发生同样的情况。这有助于得出结论,这两种输入法之间确实存在差异。

回答by Sion Cohen

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

“adb shell input keyevent eventid”肯定不会模拟真实的keyevent,因为设备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 ?

“adb shell 输入文本“sometext”怎么样,它无论如何都不是来自 pysical ......所以我想它会像在软键盘上点击一样?