Android Virtual Keyboard Input via ADB (Useful for Test Automation)
Android Virtual Keyboard Input via ADB (Useful for Test Automation)
Android Virtual Keyboard Input via ADB
ADBKeyBoard is a virtual keyboard that receives commands from system broadcast intents, which you can send text input using adb.
There is a shell command 'input', which can help you send text input to the Android system.
usage: input [text|keyevent]
input text
input keyevent
But you cannot send unicode characters using this command, as it is not designed to use it this way.
Reference : http://stackoverflow.com/questions/14224549/adb-shell-input-unicode-character
e.g.
adb shell input text '你好嗎'
is not going to work.
ADBKeyboard will help in these cases, especially in device automation and testings.
With one device or emulator connected, use these simple steps to install the keyboard:
git clone https://github.com/senzhk/ADBKeyBoard.gitcd ADBKeyBoardexport ANDROID_HOME=$HOME/Android/Sdk or edit file local.properties./gradlew installDebugadb install ADBKeyboard.apk
adb shell ime enable com.android.adbkeyboard/.AdbIME
adb shell ime set com.android.adbkeyboard/.AdbIME Usage Example:
adb shell am broadcast -a ADB_INPUT_TEXT --es msg '你好嗎? Hello?'1.1 Sending text input (base64) if (1) is not working.
adb shell am broadcast -a ADB_INPUT_B64 --es msg `echo -n '你好嗎? Hello?' | base64`Or try this script (provided by LemonNekoGH): https://gist.github.com/LemonNekoGH/f7583e0f4fa83e29dfd96d8334144650
For Windows, please try this script (provided by ssddi456): https://gist.github.com/ssddi456/889d5e8a2571a33e8fcd0ff6f1288291
Sample python script to send b64 codes (provided by sunshinewithmoonlight):
import os
import base64
chars = '的广告'
charsb64 = str(base64.b64encode(chars.encode('utf-8')))[1:]
os.system("adb shell am broadcast -a ADB_INPUT_B64 --es msg %s" %charsb64)adb shell am broadcast -a ADB_INPUT_CODE --ei code 67adb shell am broadcast -a ADB_EDITOR_CODE --ei code 2adb shell am broadcast -a ADB_INPUT_CHARS --eia chars '128568,32,67,97,116'adb shell am broadcast -a ADB_INPUT_TEXT --es mcode '4096,29' // one metaState.or
adb shell am broadcast -a ADB_INPUT_TEXT --es mcode '4096+8192,29' // two metaState.adb shell am broadcast -a ADB_CLEAR_TEXTEnable ADBKeyBoard from adb :
adb shell ime enable com.android.adbkeyboard/.AdbIME
Switch to ADBKeyBoard from adb (by robertio) :
adb shell ime set com.android.adbkeyboard/.AdbIME
Switch back to original virtual keyboard: (swype in my case...)
adb shell ime set com.nuance.swype.dtc/com.nuance.swype.input.IME
Check your available virtual keyboards:
adb shell ime list -a
Reset to default, don't care which keyboard was chosen before switch:
adb shell ime reset
You can try the apk with my debug build: https://github.com/senzhk/ADBKeyBoard/raw/master/ADBKeyboard.apk
KeyEvent Code Ref: http://developer.android.com/reference/android/view/KeyEvent.html
Editor Action Code Ref: http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html
No open issues yet, or sync has not completed.