adb shell输入unicode字符 [英] adb shell input unicode character

查看:341
本文介绍了adb shell输入unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

了解 ADB Shell输入事件中所述的基本键映射,我得到了文本的模仿输入和特殊键效果很好。但是Unicode字符呢?例如,我想使用德语QWERTZ键盘布局中的变音符号。

Knowing the basic key mappings described in ADB Shell Input Events I get the emulation of text input and special keys working quite well. But what about Unicode characters? For instance I want to use umlauts from the German QWERTZ keyboard layout.

这会让我:

$ adb shell input text ö
Killed

崩溃并

adb shell input text \xFC

在输入上打印xFC。我尝试使用 getevent 进行事件处理,但是我没有找到直接映射,我还查看了键映射文件 / system / usr / keylayout / Qwerty.kl

prints xFC on the input. I have tried to the the events with getevent but I haven't found a direct mapping, I've also looked into the keymapping file /system/usr/keylayout/Qwerty.kl

我相信唯一的可能是通过剪贴板,但是正如问题使用adb shell将文本粘贴到Android仿真器剪贴板中似乎是未知的如何在Android Ice Cream Sandwich或更高版本中使用它。.

I believe the only possibility is via the clipboard, but as pointed out in the question Pasting text into Android emulator clipboard using adb shell it seems to be unknown how to use it for Android Ice Cream Sandwich or later..

推荐答案

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

input won't work because it can only send single key event through the virtual keyboard (check the source code if you don't know what I mean).

I认为剩下的唯一方法是使用乐器。我猜您可以为您的活动创建测试,然后执行以下操作:

I think the only way left is using Instrumentation. I guess you can create a test for your Activity and then do something like this:

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

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

This will send the modified keys: àèìòù

这篇关于adb shell输入unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆