简体   繁体   English

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

[英]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/我在 developer.android.com/ 上没有找到这些命令的任何文档

Is there any trusted documentation for these commands?是否有这些命令的可信文档?

adb shell input help produces (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.您可以覆盖文本输入设备 - adb shell input keyboard text "foo"工作正常。 You can't send raw keycodes from the screen though.但是,您无法从屏幕发送原始键码。

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_KEYBOARD that 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.根据该信息,我查看了旧的 SM-G900F。 I found under /system/usr/keychars/Virtual.kcm .我在/system/usr/keychars/Virtual.kcm/system/usr/keychars/Virtual.kcm Inside of that file it maps the key events to the most common characters (mostly only ASCII).在该文件中,它将关键事件映射到最常见的字符(主要是 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!在某些设备上,我遇到了用adb shell input text "<longText>"编写的长文本(大约 200 个字符)部分丢失了 - 甚至在最后丢失了更大的部分! It looked to me depending on the manufacturer.在我看来,这取决于制造商。

There is a good description available for adb shell input * commands, just type adb shell input *命令有一个很好的描述,只需输入

adb shell input help

For adb shell keyevent commands, different keycodes are available.对于adb shell keyevent命令,可以使用不同的键码

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.我正在使用的工具(android 视图客户端)使用输入文本将文本发送到设备。 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.使用input text ,指针位置不会改变,键盘也不会显示任何按键动画。 Contrariwise, when using input tap XY to press a key, the visual behaviour is the same as a real user taping the key.相反,当使用输入点击 XY按键时,视觉行为与真实用户点击按键相同。 Also, the behaviour of the GBoard is different for both input methods.此外,两种输入法的 GBoard 行为也不同。 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 .使用input tap时不会发生同样的情况。 This helps to conclude that indeed there are differences between these two input methods.这有助于得出结论,这两种输入法之间确实存在差异。

"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 ......所以我想它会像在软键盘上点击一样?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM