-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtouch_event_record.py
executable file
·85 lines (71 loc) · 2.4 KB
/
touch_event_record.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
'''
A simple script that accepts input via stdin (piped from adb shell getevent)
and does the appropriate conversions, printing out the corresponding
adb shell sendevent commands to replay your touch actions.
@author: Seth Gregory
@version: 1.1.1
@description: adb shell getevent/sendevent conversion utility
@usage: adb shell getevent | touch_event_record.py
'''
import sys
import string
import getopt
import os
import stat
def main(argv):
# This value may vary between devices. Run an adb shell getevent and look at
# the list of event types. Set this variable to the appropriate one (e.g.,
# mine looks like this:
# add device 6: /dev/input/event1
# name: "Melfas MMSxxx Touchscreen"
event = 'event1'
# Keep a count of how many captured events we collect, just for fun.
count = 0
# No file output by default
outputfile = ''
# Get and parse commandline args/options
try:
opts, args = getopt.getopt(argv,"he:o:",["event=", "output="])
except getopt.GetoptError:
print 'touch_event_record.py [-d <eventnum>] [-o <outputfile>]'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'touch_event_record.py [-d <eventnum>] [-o <outputfile>]'
sys.exit()
elif opt in ("-e", "--event"):
event = arg
elif opt in ("-o", "--output"):
outputfile = arg
file = open(outputfile, 'w')
file.write("#!/bin/sh\n")
# Watch the buffer and convert any matching items
try:
buff = ''
while True:
buff += sys.stdin.read(1)
if buff.endswith('\n'):
if(buff.startswith('/dev/input/' + event)):
linelist = string.split(buff[:-1])
linelist[0] = 'adb shell sendevent /dev/input/' + event
linelist[1] = str(int(linelist[1], 16))
linelist[2] = str(int(linelist[2], 16))
linelist[3] = str(int(linelist[3], 16))
output = ' '.join(linelist)
print output
if outputfile != '':
file.write(output + '\n')
count = count + 1
buff = ''
# Catch KeyboardInterrupt exception on CTRL+C
except KeyboardInterrupt:
sys.stdout.flush()
if outputfile != '':
file.close()
st = os.stat(outputfile)
os.chmod(outputfile, st.st_mode | stat.S_IEXEC)
pass
print '\nExiting. ' + str(count) + ' commands captured.'
if __name__ == "__main__":
main(sys.argv[1:])