Skip to content

Instantly share code, notes, and snippets.

@kanzure
Created November 20, 2012 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanzure/4120314 to your computer and use it in GitHub Desktop.
Save kanzure/4120314 to your computer and use it in GitHub Desktop.
Fast keyboard input to Android from your development machine
#!/usr/bin/env monkeyrunner
import sys
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
print "Waiting for device..."
device = MonkeyRunner.waitForConnection()
print "Getting input arguments..."
input_text = sys.argv[1]
print "Typing.."
for token in input_text:
if token != " ":
device.type(token)
else:
device.press("KEYCODE_SPACE", MonkeyDevice.DOWN_AND_UP)
print "Done typing."
#!/bin/bash
input_text="echo hello world this is a test"
adb_input=$(
for (( i=0; i<${#input_text}; i++ )); do
current_token=${input_text:$i:1}
if [ "$current_token" = " " ]; then
echo -e "input keyevent 62"
else
echo -e "input text $current_token"
fi
done)
echo -e "$adb_input\nexit" | adb -d shell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment