11

了解ADB Shell 输入事件中描述的基本键映射后,我可以很好地模拟文本输入和特殊键。但是Unicode字符呢?例如,我想使用德国 QWERTZ 键盘布局中的变音符号。

这让我:

$ adb shell input text ö
Killed

所以它似乎崩溃了

adb shell input text \xFC

在输入上打印 xFC。我已经尝试过事件,getevent但我没有找到直接映射,我还查看了键映射文件/system/usr/keylayout/Qwerty.kl

我相信唯一的可能性是通过剪贴板,但正如在使用 adb shell 将文本粘贴到 Android 模拟器剪贴板问题中所指出的那样, 似乎不知道如何将它用于 Android Ice Cream Sandwich 或更高版本。

4

3 回答 3

20

我编写了一个接受广播意图的虚拟键盘,因此您可以通过 adb 将 unicode 字符发送到 editText 视图。

例如 adb shell am broadcast -a ADB_INPUT_TEXT --es msg "你好吗!你好!"

这是github项目: https ://github.com/senzhk/ADBKeyBoard

希望这个小项目会有所帮助。

于 2013-09-10T11:03:19.587 回答
7

其实 ADBKeyBoard 很不错!谢谢埃里克唐!

一些用于舒适使用的有用扩展:

从 adb 切换到 ADBKeyBoard:

   adb shell ime set com.android.adbkeyboard/.AdbIME   

检查您可用的 le 虚拟键盘:

ime list -a  

如果您的 shell 不接受“!”,请使用简单的引号字符 - 不要像上面的示例那样加倍 - (说明符号)

adb shell am broadcast -a ADB_INPUT_TEXT --es msg 'Accented characters here'

切换回原来的虚拟键盘:(在我的例子中是 swype ......)

adb shell ime set com.nuance.swype.dtc/com.nuance.swype.input.IME  

使用 adb over wifi 来简化你的生活...... :)

于 2014-05-05T22:07:49.323 回答
2

input不起作用,因为它只能通过虚拟键盘发送单键事件(如果您不知道我的意思,请查看源代码)。

我认为剩下的唯一方法是使用Instrumentation。我想你可以为你的活动创建一个测试,然后做这样的事情:

                final Instrumentation instrumentation = getInstrumentation();
                final long downTime = SystemClock.uptimeMillis();
                final long eventTime = SystemClock.uptimeMillis();
                
                final KeyEvent altDown = new KeyEvent(downTime, eventTime, KeyEvent.ACTION_DOWN,
                        KeyEvent.KEYCODE_GRAVE, 1, KeyEvent.META_ALT_LEFT_ON);
                final KeyEvent altUp = new KeyEvent(downTime, eventTime, KeyEvent.ACTION_UP,
                        KeyEvent.KEYCODE_GRAVE, 1, KeyEvent.META_ALT_LEFT_ON);
                
                instrumentation.sendKeySync(altDown);
                instrumentation.sendCharacterSync(KeyEvent.KEYCODE_A);
                instrumentation.sendKeySync(altUp);
                instrumentation.sendKeySync(altDown);
                instrumentation.sendCharacterSync(KeyEvent.KEYCODE_E);
                instrumentation.sendKeySync(altUp);
                instrumentation.sendKeySync(altDown);
                instrumentation.sendCharacterSync(KeyEvent.KEYCODE_I);
                instrumentation.sendKeySync(altUp);
                instrumentation.sendKeySync(altDown);
                instrumentation.sendCharacterSync(KeyEvent.KEYCODE_O);
                instrumentation.sendKeySync(altUp);
                instrumentation.sendKeySync(altDown);
                instrumentation.sendCharacterSync(KeyEvent.KEYCODE_U);
                instrumentation.sendKeySync(altUp);

这将发送修改后的键:àèìòù

2022年更新

https://stackoverflow.com/a/71367206/236465展示了另一个使用AndroidViewClient/culebraCulebraTester2-public后端的解决方案。

于 2013-01-11T07:37:52.657 回答