result = list()
for line in fp.readlines():
line = line.strip()
if not len(line) or line.startswith('#'):
continue
if line[0:3] == 'adb':
print('已经处理过了')
return False
print('处理: ' + line)
line = convert_event(line)
if not line:
continue
result.append('adb shell sendevent %s' %line)
fp.close()
print('已处理 {} 行'.format(len(result)))
try:
fp = open(getevent_file, 'w')
except Exception as e:
print('无法打开文件: '+getevent_file)
return False
send_event = "\n".join(result)
fp.write(send_event)
fp.close()
return send_event
`getevent_file = './adb_sendevent.cmd'
def readfile(path): try: fp = open(path, 'r') except Exception as e: print('无法打开文件: '+getevent_file) return False
def convert_event(getevent): try: device,event = getevent.split(':') except Exception as e: return False
def hex2int(_hex): sprintf = '%0'+str(len(_hex))+'d' return sprintf % int('0x'+str(_hex), 16)
def main(): event_new = readfile(getevent_file)
print(event_new)
if name == 'main': main()`
adb shell getevent 转换代码
转之后
adb shell sendevent /dev/input/event3 0003 0057 00001431 adb shell sendevent /dev/input/event3 0001 0330 00000001 adb shell sendevent /dev/input/event3 0001 0325 00000001 adb shell sendevent /dev/input/event3 0003 0053 00000370 adb shell sendevent /dev/input/event3 0003 0054 00000990 adb shell sendevent /dev/input/event3 0003 0048 00000007 adb shell sendevent /dev/input/event3 0003 0049 00000006 adb shell sendevent /dev/input/event3 0003 0058 00000001 adb shell sendevent /dev/input/event3 0000 0000 00000000 adb shell sendevent /dev/input/event3 0003 0058 00000001 adb shell sendevent /dev/input/event3 0000 0000 00000000 adb shell sendevent /dev/input/event3 0003 0049 00000005 adb shell sendevent /dev/input/event3 0003 0058 00000001 adb shell sendevent /dev/input/event3 0000 0000 00000000 adb shell sendevent /dev/input/event3 0003 0057 4294967295 adb shell sendevent /dev/input/event3 0001 0330 00000000 adb shell sendevent /dev/input/event3 0001 0325 00000000 adb shell sendevent /dev/input/event3 0000 0000 00000000