通过电脑向手机输入框输入特殊字符及中文

本文介绍了如何通过adb shell命令向Android手机输入框输入特殊字符和中文,包括利用adb shell ime命令、Python脚本以及图形化工具。还提到了Android Virtual Keyboard Input via ADB项目和自定义虚拟键盘的实现。
Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

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及循环录制最近操作视频的功能

您可能感兴趣的与本文相关的镜像

Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值