import re file = open("output.txt",'w') withopen('usb.txt', 'r') as lines: for line in lines: result = re.sub(r"(?<=\w)(?=(?:\w\w)+$)", ":", line) file.write(result)
变成这种形式
用大佬的脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
nums = [] keys = open('output.txt','r') posx = 0 posy = 0 for line in keys: if len(line) != 12 : continue x = int(line[3:5],16) y = int(line[6:8],16) if x > 127 : x -= 256 if y > 127 : y -= 256 posx += x posy += y btn_flag = int(line[0:2],16) # 1 for left , 2 for right , 0 for nothing if btn_flag == 1 : print posx , posy keys.close()
搞出坐标画图发现是反的,改一下y轴坐标为负即
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
nums = [] keys = open('output.txt','r') posx = 0 posy = 0 for line in keys: if len(line) != 12 : continue x = int(line[3:5],16) y = int(line[6:8],16) if x > 127 : x -= 256 if y > 127 : y -= 256 posx += x posy += y btn_flag = int(line[0:2],16) # 1 for left , 2 for right , 0 for nothing if btn_flag == 1 : print posx , -posy keys.close()