30
30
exit (3 )
31
31
32
32
33
- def divide_chunks (l , n ):
34
- for i in range (0 , len (l ), n ):
35
- yield l [i : i + n ]
36
-
37
-
38
33
def string (string ):
39
34
for char in string :
40
- pharse (char , [], True )
35
+ pharse (char , [[], [] ], True )
41
36
sleep (string_delay / 100 )
42
37
43
38
@@ -48,77 +43,74 @@ def pharse(line, known, deltrue):
48
43
command = line .split ()
49
44
else :
50
45
command = [" " ]
51
- if not deltrue :
52
- if command [0 ] == "DELAY" :
53
- sleep (int (command [1 ]) / 100 )
54
- return
55
- elif command [0 ] == "REM" :
56
- return
57
- elif command [0 ] == "REPEAT" :
58
- return # todo
59
- else :
60
- sleep (default_delay / 100 )
61
- if command [0 ] == "STRING" :
62
- string (" " .join (command [1 :]))
46
+ if command [0 ] == "DELAY" :
47
+ sleep (int (command [1 ]) / 100 )
63
48
return
49
+ elif command [0 ] == "REM" :
50
+ return
51
+ elif command [0 ] == "REPEAT" :
52
+ return # todo
64
53
elif command [0 ] == "DEFAULTCHARDELAY" :
65
54
string_delay = int (command [1 ])
66
55
return
67
56
elif command [0 ] == "DEFAULTDELAY" :
68
57
default_delay = int (command [1 ])
69
58
return
70
- elif command [0 ] in keymap .aliasmap :
71
- pharse (keymap .aliasmap [command [0 ]] + " " + " " .join (command [1 :]), known , True )
59
+ else :
60
+ if not deltrue :
61
+ sleep (default_delay / 100 )
62
+ if command [0 ] == "STRING" :
63
+ string (line [len ("STRING " ) :])
72
64
return
73
65
elif command [0 ] in keymap .commap :
74
- known .append (keymap .commap [command [0 ]])
66
+ known [ 0 ] .append (keymap .commap [command [0 ]])
75
67
pharse (" " .join (command [1 :]), known , True )
76
68
return
77
69
elif command [0 ] in keymap .c1map :
78
- known .append (keymap .c1map [command [0 ]])
70
+ known [ 1 ] .append (keymap .c1map [command [0 ]])
79
71
out (known )
80
72
return
81
73
elif command [0 ] in keymap .c2map :
82
74
pharse (keymap .c2map [command [0 ]], known , True )
83
75
return
76
+ elif command [0 ] in keymap .aliasmap :
77
+ pharse (keymap .aliasmap [command [0 ]] + " " + " " .join (command [1 :]), known , True )
78
+ return
84
79
else :
85
80
exit (2 )
86
81
87
82
88
83
def out (ccl ):
89
- # ccl_part=list(divide_chunks(ccl, n))
90
- i = 2
91
- if len (ccl ) == 1 :
92
- rep = (chr (0 ) * 2 ) + chr (ccl [0 ])
93
- e = 3
84
+ rep = ""
85
+ if len (ccl [0 ]) > 0 :
86
+ for e in ccl [0 ]:
87
+ rep = rep + chr (e )
94
88
else :
95
- rep = ""
96
- for e in range (len (ccl ) - 1 ):
97
- rep = rep + chr (ccl [e ])
98
- e = e + 2
99
- rep = rep + chr (0 ) + chr (ccl [e - 1 ])
100
- rep = rep + (chr (0 ) * (8 - e ))
89
+ rep = rep + chr (0 )
90
+ rep = rep + chr (0 )
91
+ for e in ccl [1 ]:
92
+ rep = rep + chr (e )
93
+ rep = rep + chr (0 ) * (8 - len (rep ))
101
94
with open ("/dev/hidg0" , "rb+" ) as fd :
102
95
fd .write (rep .encode ())
103
96
fd .write ((chr (0 ) * 8 ).encode ())
104
97
105
98
106
- # argparse fix
107
99
def main ():
108
100
if piargs .input is not None :
109
101
file1 = open (piargs .input , "r" )
110
102
while True :
111
103
line = file1 .readline ()
112
104
if not line :
113
105
break
114
- pharse (line .strip (), [], False )
106
+ pharse (line .strip (), [[], [] ], False )
115
107
file1 .close ()
116
108
else :
117
109
while True :
118
110
line = input ()
119
111
if not line :
120
112
break
121
- pharse (line .strip (), [], False )
113
+ pharse (line .strip (), [[], [] ], False )
122
114
123
115
124
116
main ()
0 commit comments