Skip to content Skip to sidebar Skip to footer

Typing On An Android Device Straight From Computer?

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

Solution 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


Solution 2:

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


Solution 3:

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'"

Solution 4:

You can see how it's done in talkmyphone.

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


Solution 5:

When using zsh, here is a more robust function to feed text to Android:

function adbtext() {
    while read -r line; do
        adb shell input text ${(q)${line// /%s}}
    done
}

While Zsh quoting may be slightly different from a regular POSIX shell, I didn't find anything it wouldn't work on. Dan's answer is missing for example > which also needs to be escaped.

I am using it with pass show ... | adbtext.


Post a Comment for "Typing On An Android Device Straight From Computer?"