Typing on an Android Device straight from computer

2020-05-20 08:10发布

Can you use ADB to type directly on an android device from a computer? If so, how?

标签: android adb
4条回答
等我变得足够好
2楼-- · 2020-05-20 08:49

As Manuel said, you can use adb shell input text, but you need to replace spaces with %s, as well as handle quotes. Here's a simple bash script to make that very easy:

#!/bin/bash

text=$(printf '%s%%s' ${@})  # concatenate and replace spaces with %s
text=${text%%%s}  # remove the trailing %s
text=${text//\'/\\\'}  # escape single quotes
text=${text//\"/\\\"}  # escape double quotes
# echo "[$text]"  # debugging

adb shell input text "$text"

Save as, say, atext and make executable. Then you can invoke the script without quotes...

atext Hello world!

...unless you need to send quotes, in which case you do need to put them between the other type of quotes (this is a shell limitation):

atext "I'd" like it '"shaken, not stirred"'

enter image description here

查看更多
手持菜刀,她持情操
3楼-- · 2020-05-20 08:52

To avoid expansion/evaluation of the text parameter (i.e. for special characters like '$' or ';'), you could wrap them into quotes like this:

adb shell "input text 'insert your text here'"
查看更多
别忘想泡老子
4楼-- · 2020-05-20 09:07

Although this question is rather old, I'd like to add this answer:

You may use adb shell input keyevent KEYCODE resp. adb shell input text "mytext". A list of all keycodes can be found here

查看更多
贪生不怕死
5楼-- · 2020-05-20 09:13

You can see how it's done in talkmyphone.

They are using Jabber, but it might be useful for you.

查看更多
登录 后发表回答