16

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.

This gets me:

$ adb shell input text ö
Killed

So it seems to crash and

adb shell input text \xFC

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

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

3 Answers 3

26

I wrote a virtual keyboard that accept broadcast intent, so you can send unicode characters to the editText view via adb.

for e.g. adb shell am broadcast -a ADB_INPUT_TEXT --es msg "你好嗎! Hello!"

Here is the github project: https://github.com/senzhk/ADBKeyBoard

Hope this little project would help.

1
  • thank you very much for patching a lack in android. you're the real mvp !
    – y_nk
    Nov 13, 2016 at 21:41
10

Actually ADBKeyBoard is very good! Thanks for Eric Tang !

Some useful extensions for comfortable usage:

Switch to ADBKeyBoard from adb:

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

Check your available le virtual keyboards:

ime list -a  

Use simple quote characters -not double as in example above- if your shell not accepts "!" (explanation sign)

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

Switch back to original virtual keyboard: (swype in my case...)

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

Use adb over wifi to simplify your life... :)

2
  • 3
    This requires the app to be installed on the device. Isn't there any way to achieve it using "adb" itself? Sep 29, 2014 at 11:03
  • Thanks, I don't know adb can connect with WIFI before now, it help me a lot.
    – zw963
    Feb 1, 2016 at 3:29
3

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 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: àèìòù

update 2022

https://stackoverflow.com/a/71367206/236465 shows another solution using AndroidViewClient/culebra and CulebraTester2-public backend.

2
  • While this seems to work for the accented letters you list, I don't think it works for German umlauts such as äöü. Do you know what key combinations to use to produce these?
    – FD_
    May 9, 2016 at 14:13
  • 1
    @FD_ Hi, Finally I found the answer. Firstly, on this page, Key Map you can know the unicodes of combining diacritical dead key characters. '\u0300': Grave accent. à '\u0301': Acute accent. á '\u0302': Circumflex accent. â '\u0303': Tilde accent. ã '\u0308': Umlaut accent. ä and on this page Virtual.kcm you can know how the unicode can be constructed.
    – Shawn.G
    Apr 28, 2021 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.