forked from Nutriz/android-touch-record-replay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuman_readable_data.py
executable file
·39 lines (31 loc) · 1.18 KB
/
human_readable_data.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
import subprocess
import datetime
import sys
import csv
#Input your touchscreen device name to the file
#cmdline usage: python human_readable_data.py /dev/input/event$ filepath
touchscreen = sys.argv[1]
outputpath = sys.argv[2]
headers = ["Timestamp", "Type", "Code", "Value"]
with open(outputpath, 'w') as writeFile:
writer = csv.writer(writeFile)
writer.writerow(headers)
writeFile.close()
p = subprocess.Popen(['adb', 'exec-out', 'getevent', '-lt', touchscreen], stdout=subprocess.PIPE)
while True:
output = p.stdout.readline()
if output == '' and p.poll() is not None:
break
if output:
time, event_data = output.split("]", 1)
event_type, event_code, event_value = event_data.split()
try:
# convert hexadecimal to int
event_value = int(event_value, 16)
except ValueError:
pass
with open(outputpath, 'a') as writeFile:
writer = csv.writer(writeFile)
writer.writerow([datetime.datetime.now(), event_type, event_code, event_value])
writeFile.close()
print("[ {}] {} {} {}".format(datetime.datetime.now(), event_type, event_code, event_value))