使用adb輸入中文字符

由於目前adb shell input 不支持unicode字符輸入,因此繞個小彎路實現中文輸入

鏈接:https://github.com/bingwei/inputchineseviaadb


安裝apk文件(可以從pyscript下找到)

運行python pyscript/testScript.py試驗

最終輸入的字符將被保存到粘貼板裏。



原理:使用unicode字符原樣輸出,然後再轉化爲encoded字符。


核心代碼

輸入端:

1. 標識腳本文件爲支持utf-8字符集

#!-*- coding: utf-8 -*-

2. 使用%r原樣輸入unicode字符

os.system("adb shell input text %r"%u"黑色“)


轉換端(apk):

1. 輸入到editText中的字符爲轉義後的unicode,因此需要反轉義,這裏用到了StringEscapeUtils

下載:http://commons.apache.org/lang/download_lang.cgi

API:http://commons.apache.org/lang/api-2.1/org/apache/commons/lang/StringEscapeUtils.html 

import org.apache.commons.lang3.StringEscapeUtils;
StringEscapeUtils.unescapeJava(editText.getText().toString().replace("u\\", "\\"))
反轉義之後複製到clipboard就可以了


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章