Turning the output from getevent into something something that can be used

My end goal was to to be able to “doodle” on the android screen, with a script.  I can’t do the math to generate the image I want, so I ran the adb shell command “getevent” then using the mouse, I drew on the screen.

However the output isn’t immediately usable, first there was the minor problem of it containing a colon which would throw an error when I tried to run it.  The second and bigger issue, is that the getevent command captures everything in hexadecimal, but the command sendevent, requires everything to be in decimal.  Since monkeyrunner is basically python (the docs say jython, but I haven’t used anything that advance yet), I wrote a python script, that takes an input file containing a bunch of lines that look like this:

/dev/input/event0: 0003 0000 00000073
/dev/input/event0: 0003 0001 000000a8
/dev/input/event0: 0001 014a 00000001
/dev/input/event0: 0000 0000 00000000
/dev/input/event0: 0003 0001 000000a4

And created a new output file with adb shell commands that look like this:

adb shell sendevent /dev/input/event0 3 0 115
adb shell sendevent /dev/input/event0 3 1 168
adb shell sendevent /dev/input/event0 1 330 1
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 3 1 164

Which can be run and do the drawing for me on the screen.  This worked, but running a bunch of adb shell commands is really, really slow.  So I tweaked my python script, and instead have to create something like:

echo Running – signature function
sendevent /dev/input/event0 3 0 115
sendevent /dev/input/event0 3 1 168
sendevent /dev/input/event0 1 330 1
sendevent /dev/input/event0 0 0 0
sendevent /dev/input/event0 3 1 164
sendevent /dev/input/event0 0 0 0

This is copied to the device, and run as a local script and runs at an ok speed (not really fast, but much faster than adb shell commands) – the python script prints out instructions with the exact command to run, to copy the file to the device and what to execute it run it.  I will post the python separately, I am new to this code so the code isn’t prefect, but it works and meets my needs.ew

The steps are

  1. Run the app (I did it in the emulator)
  2. Run the command adb shell getevent, om whatever screen you want to doodle/draw on – the output is dumped to the screen
  3. Capture that output when you are done (copy it, usually by right clicking and choosing mark, highlight the area and then hit enter)
    1. Paste the info into notepad, and save it to any file name you want (i.e. captured.dat)
  4. Run the script
    1. hex_to_dec.py captured.dat
      1. catpured.bat is the input data for the script
  5. The script runs pretty fast and kicks out a file captured.scr (the code can be updated to name the file anything)
    1. The script prints out instructions for coping the script to the device and for running the script, that looks something like this

C:\>hex_to_dec.py raw_captured_sig.dat
Processing complete
File created: raw_captured_sig.scr

Copy file to the device
adb push raw_captured_sig.scr /sdcard/raw_captured_sig.scr

Run the script
adb shell sh /sdcard/raw_captured_sig.scr


About thewere42

Software tester by day - parent by night - with too many interest and too little time - spanning cooking, going green, photography, technology, transportation, and the world in general

Posted on June 21, 2012, in Android adb Commands, Android MonekyRunner, Python Script and tagged , , , , , , , . Bookmark the permalink. 4 Comments.

  1. Thanks for your post and the python script! It works fine for me and have saved me a lot of time. Thank you!

  2. there’s a syntax error in your script at line 89

  3. Ashish Mishra

    There is some missing code in your python script at line number 89. Could you please update it. Let know if/when done. Thanks in advance.

    • When I return to it, I haven’t worked on Android for a while – I have been assigned IOS stuf for the last 1 1/2 years

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: