问题
Can you use ADB to type directly on an android device from a computer? If so, how?
回答1:
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
回答2:
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'"
回答3:
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"'
回答4:
You can see how it's done in talkmyphone.
They are using Jabber
, but it might be useful for you.
来源:https://stackoverflow.com/questions/3978299/typing-on-an-android-device-straight-from-computer