adb shell 输入文字
通过adb shell指令向手机输入框输入指定的内容,包括特性字符、中文等。
adb shell ime使用
usage: ime list [-a] [-s]
ime enable ID
ime disable ID
ime set ID
The list command prints all enabled input methods. Use
the -a option to see all input methods. Use
the -s option to see only a single summary line of each.
The enable command allows the given input method ID to be used.
The disable command disallows the given input method ID from use.
The set command switches to the given input method ID.
获取当前使用的软键盘
abc:~ likunlun$ adb shell settings get secure default_input_method
com.baidu.input_mi/.ImeService
通过Python语言获取:
@staticmethod
def getCurKeyboardId():
"""
获取当前使用的软键盘的ID
:return: 当前使用的软键盘的ID
"""
out, err = ShellUtil.exec('adb shell settings get secure default_input_method')
if out:
return out
out, err = ShellUtil.exec('adb shell ime list -s')
if err or not out:
return None
items = out.split("\n")
for item in items:
if ANDROID_TEST_ASSIST_TOOL_PACKAGE_NAME not in item:
return item.strip()
return None
向手机输入框输入文字
参考 Android Virtual Keyboard Input via ADB 项目,实现自定义虚拟键盘,接收处理 adb shell 指令传输过来的文字填充到输入框。
adb shell am broadcast -a ADB_INPUT_TEXT --es msg ‘你好嗎? Hello?’
For Mac/Linux, you can use the latest base64 input type with base64 command line tool:
adb shell am broadcast -a ADB_INPUT_B64 --es msg
echo -n '你好嗎? Hello?' | base64
通过Python语言传输:
@staticmethod
def inputBase64Text(text):
charsBase64 = str(base64.b64encode(text.encode('utf-8')))[1:]
curKeyboardId = AdbUtil.getCurKeyboardId()
ShellUtil.exec("adb shell ime set com.lkl.androidtestassisttool/.adbkeyboard.AdbIME")
ShellUtil.exec("adb shell am broadcast -a ADB_INPUT_B64 --es msg %s" % charsBase64)
ShellUtil.exec("adb shell ime set {}".format(curKeyboardId))
使用图形化工具

结果:

参考文献
https://github.com/senzhk/ADBKeyBoard
自定义开发测试辅助工具
辅助Android apk测试抓取log及循环录制最近操作视频的功能
本文介绍了如何通过adb shell命令向Android手机输入框输入特殊字符和中文,包括利用adb shell ime命令、Python脚本以及图形化工具。还提到了Android Virtual Keyboard Input via ADB项目和自定义虚拟键盘的实现。
1894

被折叠的 条评论
为什么被折叠?



