Android: recording key presses for later scriptable playback
Recently I needed to be able to press the VOLUME_UP and VOLUME_DOWN keys at the same time for 3 seconds. I find writing a post rather than relying on StackOverflow posts is more helpful, especially when there is a little more that needs to be said. While this is documented in the README of the code where I use it, I think it makes a fairly good post on it’s own.
I have found the best way to reverse engineer button presses is to
- Identify the device -
/dev/input/device[n]
- Record the usage
- Open up a [hex editor][5] and identify the ups and downs e.g. this is a VOLUME_UP, KEY_DOWN:
00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 0a | 0b | 0c | 0d | 0e | 0f
03 | 88 | 61 | 60 | 9e | 5e | 0a | 00 | 01 | 00 | 73 | 00 | 01 | 00 | 00 | 00
03 | 88 | 61 | 60 | 9e | 5e | 0a | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00
if you run adb shell getevent -l
and adb shell getevent -lp
you’ll find that 73
is the key (position 0a, specifically, the VOLUME_UP key) and position 0c is the event type (down). Every press has a reset (all 00’s).
- Create a script with the timing involved as well as the key presses. Timing is not recorded with the device buffer
Comments
No comments found for this article.
Join the discussion for this article on github. Comments appear on this page instantly.