Simplifying repetitive text input with adb
For a long time — probably since I configured my WLAN access point with a long and complex password (to the annoyance of visitors) — I’ve been using the input
command on the Android shell to automate the entry of commonly-used or annoying-to-type text on my phone.
Running the command adb shell input
on my Nexus 4, I get the following documentation:
usage: input ...
input text <string>
input keyevent <key code number or name>
input [touchscreen|touchpad] tap <x> <y>
input [touchscreen|touchpad] swipe <x1> <y1> <x2> <y2>
input trackball press
input trackball roll <dx> <dy>
By far, the most common sub-command I use is text
, e.g. for typing in test usernames while working on an Android app:
adb shell input text test.account+1370558502@gmail.com
This types the text into the active text field on your device or emulator, one character at a time.
Given how often I use the command, I also have a shell alias which expands it
to adb shell input text
.
One caveat is that the command does not appear to accept spaces, even if the string is quoted. So while this is great for email addresses, or long hex strings etc., it’s not so practical for entering passages of text.
However, the keyevent
sub-command lets you send arbitrary KeyEvent
keycodes. For example, to send the Enter key:
adb shell input keyevent ENTER
This maps to the KEYCODE_ENTER
constant which duly presses enter on the currently-focused input field.
Handy.