Skip to content

Commit 15d9046

Browse files
authored
Merge branch 'master' into Complete-Layout-US
2 parents 10e4094 + a77a113 commit 15d9046

File tree

3 files changed

+85
-54
lines changed

3 files changed

+85
-54
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Piduck is a program with which you can easily use your Raspberry Pi Zero as a USB HID keyboard. It uses the scripting language [Ducky-Script-v1].
33

44
The Project is in Beta and help is needed.
5-
The function `REPEAT`, `FN` and other special character and keys are missing. For now, only the US keyboard layout is available.
5+
For now, only the US keyboard layout is available.
66

77
## Contributions
88
All contributions are welcome!

Usb-Hut1_12v2.pdf

950 KB
Binary file not shown.

piduck.py

Lines changed: 84 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,11 @@
22
import argparse
33
from importlib import import_module
44
from time import sleep
5+
import sys
56

6-
key_layout = "us"
7-
default_delay = 10
8-
string_delay = 1
97

10-
aliasmap = {
11-
"CTRL": "LCTRL",
12-
"SHIFT": "LSHIFT",
13-
"ALT": "LALT",
14-
"META": "LMETA",
15-
"CONTROL": "CTRL",
16-
"GUI": "META",
17-
"ESCAPE": "ESC",
18-
"RIGHTARROW": "RIGHT",
19-
"LEFTARROW": "LEFT",
20-
"DOWNARROW": "DOWN",
21-
"UPARROW": "UP",
22-
"CTRL-ALT": "CTRL ALT",
23-
"CTRL-SHIFT": "CTRL SHIFT",
24-
"DEFAULT_DELAY": "DEFAULTDELAY",
25-
" ": "SPACE",
26-
"BREAK": "PAUSE",
27-
}
28-
29-
piparser = argparse.ArgumentParser()
30-
piparser.add_argument("-i", "--input", help="File input")
31-
piparser.add_argument(
32-
"-l", "--keyboardlayoutcode", help="Language codes specified by ISO639-1:2002"
33-
)
34-
piparser.add_argument("-d", "--defaultdelay", help="The default delay of execution")
35-
piparser.add_argument(
36-
"-s", "--defaultchardelay", help="The default char delay of execution"
37-
)
38-
piargs = piparser.parse_args()
39-
if piargs.keyboardlayoutcode is not None:
40-
key_layout = piargs.keyboardlayoutcode
41-
if piargs.defaultdelay is not None:
42-
default_delay = piargs.defaultdelay
43-
if piargs.defaultchardelay is not None:
44-
string_delay = piargs.defaultchardelay
45-
try:
46-
keymap = import_module("pd_key_maps.keymap_" + key_layout)
47-
except ModuleNotFoundError:
48-
exit(3)
8+
def eprint(*args, **kwargs):
9+
print(*args, file=sys.stderr, **kwargs)
4910

5011

5112
def string(string):
@@ -57,17 +18,25 @@ def string(string):
5718
def pharse(line, known, deltrue):
5819
global default_delay
5920
global string_delay
60-
if line != " ":
61-
command = line.split()
62-
else:
21+
if line == "":
22+
return
23+
elif line == " ":
6324
command = [" "]
25+
else:
26+
command = line.split()
6427
if command[0] == "DELAY":
6528
sleep(int(command[1]) / 100)
6629
return
6730
elif command[0] == "REM":
6831
return
6932
elif command[0] == "REPEAT":
70-
return # todo
33+
try:
34+
for i in range(int(command[1])):
35+
pharse(last_line.strip(), [[], []], False)
36+
return # todo
37+
except RecursionError:
38+
eprint("You can not repeat the repeat")
39+
exit(4)
7140
elif command[0] == "DEFAULTCHARDELAY":
7241
string_delay = int(command[1])
7342
return
@@ -78,23 +47,30 @@ def pharse(line, known, deltrue):
7847
if not deltrue:
7948
sleep(default_delay / 100)
8049
if command[0] == "STRING":
81-
string(line[len("STRING ") :])
50+
string(line[len(command[0] + " ") :])
8251
return
8352
elif command[0] in keymap.commap:
8453
known[0].append(keymap.commap[command[0]])
85-
pharse(" ".join(command[1:]), known, True)
54+
if len(command) > 1:
55+
pharse(" ".join(command[1:]), known, True)
56+
else:
57+
out(known)
8658
return
8759
elif command[0] in keymap.c1map:
8860
known[1].append(keymap.c1map[command[0]])
89-
out(known)
61+
if len(command) > 1:
62+
pharse(" ".join(command[1:]), known, True)
63+
else:
64+
out(known)
9065
return
9166
elif command[0] in keymap.c2map:
92-
pharse(keymap.c2map[command[0]], known, True)
67+
pharse(keymap.c2map[command[0]] + " " + " ".join(command[1:]), known, True)
9368
return
9469
elif command[0] in aliasmap:
9570
pharse(aliasmap[command[0]] + " " + " ".join(command[1:]), known, True)
9671
return
9772
else:
73+
eprint('Could not find "' + command[0] + '"')
9874
exit(2)
9975

10076

@@ -115,21 +91,76 @@ def out(ccl):
11591

11692

11793
def main():
94+
global last_line
11895
if piargs.input is not None:
11996
file1 = open(piargs.input, "r")
12097
while True:
12198
line = file1.readline()
12299
if not line:
123100
break
124101
pharse(line.strip(), [[], []], False)
102+
last_line = line
125103
file1.close()
126104
else:
127105
while True:
128-
line = input()
106+
try:
107+
line = input()
108+
except EOFError:
109+
break
129110
if not line:
130111
break
131112
pharse(line.strip(), [[], []], False)
113+
last_line = line
114+
132115

116+
if __name__ == "__main__":
117+
last_line = ""
118+
key_layout = "us"
119+
default_delay = 10
120+
string_delay = 1
121+
122+
aliasmap = {
123+
"CTRL": "LCTRL",
124+
"SHIFT": "LSHIFT",
125+
"ALT": "LALT",
126+
"META": "LMETA",
127+
"CONTROL": "CTRL",
128+
"GUI": "META",
129+
"ESCAPE": "ESC",
130+
"RIGHTARROW": "RIGHT",
131+
"LEFTARROW": "LEFT",
132+
"DOWNARROW": "DOWN",
133+
"UPARROW": "UP",
134+
"CTRL-ALT": "CTRL ALT",
135+
"CTRL-SHIFT": "CTRL SHIFT",
136+
"DEFAULT_DELAY": "DEFAULTDELAY",
137+
" ": "SPACE",
138+
"BREAK": "PAUSE",
139+
}
133140

134-
main()
135-
exit(0)
141+
piparser = argparse.ArgumentParser()
142+
piparser.add_argument("-i", "--input", help="File input")
143+
piparser.add_argument(
144+
"-l", "--keyboardlayoutcode", help="Language codes specified by ISO639-1:2002"
145+
)
146+
piparser.add_argument("-d", "--defaultdelay", help="The default delay of execution")
147+
piparser.add_argument(
148+
"-s", "--defaultchardelay", help="The default char delay of execution"
149+
)
150+
piargs = piparser.parse_args()
151+
if piargs.keyboardlayoutcode is not None:
152+
key_layout = piargs.keyboardlayoutcode
153+
if piargs.defaultdelay is not None:
154+
default_delay = piargs.defaultdelay
155+
if piargs.defaultchardelay is not None:
156+
string_delay = piargs.defaultchardelay
157+
try:
158+
keymap = import_module("pd_key_maps.keymap_" + key_layout)
159+
except ModuleNotFoundError:
160+
eprint('Keymap "' + key_layout + '" could not be found')
161+
exit(3)
162+
try:
163+
main()
164+
except KeyboardInterrupt:
165+
pass
166+
exit(0)

0 commit comments

Comments
 (0)