-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsolve.py
109 lines (94 loc) · 2.36 KB
/
solve.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
import sys
KEY_CODES = {
0x04: ['a', 'A'],
0x05: ['b', 'B'],
0x06: ['c', 'C'],
0x07: ['d', 'D'],
0x08: ['e', 'E'],
0x09: ['f', 'F'],
0x0a: ['g', 'G'],
0x0b: ['h', 'H'],
0x0c: ['i', 'I'],
0x0d: ['j', 'J'],
0x0e: ['k', 'K'],
0x0f: ['l', 'L'],
0x10: ['m', 'M'],
0x11: ['n', 'N'],
0x12: ['o', 'O'],
0x13: ['p', 'P'],
0x14: ['q', 'Q'],
0x15: ['r', 'R'],
0x16: ['s', 'S'],
0x17: ['t', 'T'],
0x18: ['u', 'U'],
0x19: ['v', 'V'],
0x1a: ['w', 'W'],
0x1b: ['x', 'X'],
0x1c: ['y', 'Y'],
0x1d: ['z', 'Z'],
0x1e: ['1', '!'],
0x1f: ['2', '@'],
0x20: ['3', '#'],
0x21: ['4', '$'],
0x22: ['5', '%'],
0x23: ['6', '^'],
0x24: ['7', '&'],
0x25: ['8', '*'],
0x26: ['9', '('],
0x27: ['0', ')'],
0x28: ['[ENTER]', '[ENTER]'],
0x29: ['[ESC]', '[ESC]'],
0x2a: ['[BACKSPACE]', '[BACKSPACE]'],
0x2b: ['\t', '\t'],
0x2c: [' ', ' '],
0x2d: ['-', '_'],
0x2e: ['=', '+'],
0x2f: ['[', '{'],
0x30: [']', '}'],
0x32: ['#', '~'],
0x33: [';', ':'],
0x34: ["'", '"'],
0x36: [',', '<'],
0x37: ['.', '>'],
0x38: ['/', '?'],
0x39: ['[CAPSLOCK]', '[CAPSLOCK]'],
0x4f: ['[RIGHT]', '[RIGHT]'],
0x50: ['[LEFT]', '[LEFT]'],
0x51: ['[DOWN]', '[DOWN]'],
0x52: ['[UP]', '[UP]']
}
def decode(datas):
cursor_x = 0
cursor_y = 0
offset_current_line = 0
lines = ['']
output = ''
for data in datas:
shift = int(data[:2], 16)
key = int(data[4:6], 16)
if key == 0:
continue
if shift != 0:
shift = 1
if KEY_CODES[key][shift] == '[RIGHT]':
cursor_x += 1
elif KEY_CODES[key][shift] == '[LEFT]':
cursor_x -= 1
elif KEY_CODES[key][shift] == '[ENTER]':
lines.append('')
lines[cursor_y] += output
cursor_x = 0
cursor_y += 1
output = ''
else:
output = output[:cursor_x] + KEY_CODES[key][shift] + output[cursor_x:]
cursor_x += 1
print(data.strip(), KEY_CODES[key][shift])
if lines == ['']:
lines[0] = output
if output != '' and output not in lines:
lines[cursor_y] += output
return '\n'.join(lines)
if __name__ == '__main__':
print('\n' + decode(sys.stdin))