3030 exit (3 )
3131
3232
33- def divide_chunks (l , n ):
34- for i in range (0 , len (l ), n ):
35- yield l [i : i + n ]
36-
37-
3833def string (string ):
3934 for char in string :
40- pharse (char , [], True )
35+ pharse (char , [[], [] ], True )
4136 sleep (string_delay / 100 )
4237
4338
@@ -48,77 +43,74 @@ def pharse(line, known, deltrue):
4843 command = line .split ()
4944 else :
5045 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 )
6348 return
49+ elif command [0 ] == "REM" :
50+ return
51+ elif command [0 ] == "REPEAT" :
52+ return # todo
6453 elif command [0 ] == "DEFAULTCHARDELAY" :
6554 string_delay = int (command [1 ])
6655 return
6756 elif command [0 ] == "DEFAULTDELAY" :
6857 default_delay = int (command [1 ])
6958 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 " ) :])
7264 return
7365 elif command [0 ] in keymap .commap :
74- known .append (keymap .commap [command [0 ]])
66+ known [ 0 ] .append (keymap .commap [command [0 ]])
7567 pharse (" " .join (command [1 :]), known , True )
7668 return
7769 elif command [0 ] in keymap .c1map :
78- known .append (keymap .c1map [command [0 ]])
70+ known [ 1 ] .append (keymap .c1map [command [0 ]])
7971 out (known )
8072 return
8173 elif command [0 ] in keymap .c2map :
8274 pharse (keymap .c2map [command [0 ]], known , True )
8375 return
76+ elif command [0 ] in keymap .aliasmap :
77+ pharse (keymap .aliasmap [command [0 ]] + " " + " " .join (command [1 :]), known , True )
78+ return
8479 else :
8580 exit (2 )
8681
8782
8883def 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 )
9488 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 ))
10194 with open ("/dev/hidg0" , "rb+" ) as fd :
10295 fd .write (rep .encode ())
10396 fd .write ((chr (0 ) * 8 ).encode ())
10497
10598
106- # argparse fix
10799def main ():
108100 if piargs .input is not None :
109101 file1 = open (piargs .input , "r" )
110102 while True :
111103 line = file1 .readline ()
112104 if not line :
113105 break
114- pharse (line .strip (), [], False )
106+ pharse (line .strip (), [[], [] ], False )
115107 file1 .close ()
116108 else :
117109 while True :
118110 line = input ()
119111 if not line :
120112 break
121- pharse (line .strip (), [], False )
113+ pharse (line .strip (), [[], [] ], False )
122114
123115
124116main ()
0 commit comments