|
6 | 6 | import digitalio
|
7 | 7 | from board import *
|
8 | 8 |
|
9 |
| -duckyCommands = ["WINDOWS", "GUI", "APP", "MENU", "SHIFT", "ALT", "CONTROL", "CTRL", "DOWNARROW", "DOWN", |
10 |
| -"LEFTARROW", "LEFT", "RIGHTARROW", "RIGHT", "UPARROW", "UP", "BREAK", "PAUSE", "CAPSLOCK", "DELETE", "END", |
11 |
| -"ESC", "ESCAPE", "HOME", "INSERT", "NUMLOCK", "PAGEUP", "PAGEDOWN", "PRINTSCREEN", "SCROLLLOCK", "SPACE", |
12 |
| -"TAB", "ENTER", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", |
13 |
| -"u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", |
14 |
| -"Q", "R", "S", "T", "U", "V", "W", "X", "Y", " Z", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12"] |
15 |
| - |
16 |
| -keycodeCommands = [Keycode.WINDOWS, Keycode.GUI, Keycode.APPLICATION, Keycode.APPLICATION, Keycode.SHIFT, Keycode.ALT, Keycode.CONTROL, |
17 |
| -Keycode.CONTROL, Keycode.DOWN_ARROW, Keycode.DOWN_ARROW ,Keycode.LEFT_ARROW, Keycode.LEFT_ARROW, Keycode.RIGHT_ARROW, Keycode.RIGHT_ARROW, |
18 |
| -Keycode.UP_ARROW, Keycode.UP_ARROW, Keycode.PAUSE, Keycode.PAUSE, Keycode.CAPS_LOCK, Keycode.DELETE, Keycode.END, Keycode.ESCAPE, |
19 |
| -Keycode.ESCAPE, Keycode.HOME, Keycode.INSERT, Keycode.KEYPAD_NUMLOCK, Keycode.PAGE_UP, Keycode.PAGE_DOWN, Keycode.PRINT_SCREEN, |
20 |
| -Keycode.SCROLL_LOCK, Keycode.SPACE, Keycode.TAB, Keycode.ENTER, Keycode.A, Keycode.B, Keycode.C, Keycode.D, Keycode.E, Keycode.F, Keycode.G, |
21 |
| -Keycode.H, Keycode.I, Keycode.J, Keycode.K, Keycode.L, Keycode.M, Keycode.N, Keycode.O, Keycode.P, Keycode.Q, Keycode.R, Keycode.S, Keycode.T, |
22 |
| -Keycode.U, Keycode.V, Keycode.W, Keycode.X, Keycode.Y, Keycode.Z, Keycode.A, Keycode.B, Keycode.C, Keycode.D, Keycode.E, Keycode.F, |
23 |
| -Keycode.G, Keycode.H, Keycode.I, Keycode.J, Keycode.K, Keycode.L, Keycode.M, Keycode.N, Keycode.O, Keycode.P, |
24 |
| -Keycode.Q, Keycode.R, Keycode.S, Keycode.T, Keycode.U, Keycode.V, Keycode.W, Keycode.X, Keycode.Y, Keycode.Z, |
25 |
| -Keycode.F1, Keycode.F2, Keycode.F3, Keycode.F4, Keycode.F5, Keycode.F6, Keycode.F7, Keycode.F8, Keycode.F9, |
26 |
| -Keycode.F10, Keycode.F11, Keycode.F12] |
| 9 | +duckyCommands = { |
| 10 | + 'WINDOWS': Keycode.WINDOWS, 'GUI': Keycode.GUI, |
| 11 | + 'APP': Keycode.APPLICATION, 'MENU': Keycode.APPLICATION, 'SHIFT': Keycode.SHIFT, |
| 12 | + 'ALT': Keycode.ALT, 'CONTROL': Keycode.CONTROL, 'CTRL': Keycode.CONTROL, |
| 13 | + 'DOWNARROW': Keycode.DOWN_ARROW, 'DOWN': Keycode.DOWN_ARROW, 'LEFTARROW': Keycode.LEFT_ARROW, |
| 14 | + 'LEFT': Keycode.LEFT_ARROW, 'RIGHTARROW': Keycode.RIGHT_ARROW, 'RIGHT': Keycode.RIGHT_ARROW, |
| 15 | + 'UPARROW': Keycode.UP_ARROW, 'UP': Keycode.UP_ARROW, 'BREAK': Keycode.PAUSE, |
| 16 | + 'PAUSE': Keycode.PAUSE, 'CAPSLOCK': Keycode.CAPS_LOCK, 'DELETE': Keycode.DELETE, |
| 17 | + 'END': Keycode.END, 'ESC': Keycode.ESCAPE, 'ESCAPE': Keycode.ESCAPE, 'HOME': Keycode.HOME, |
| 18 | + 'INSERT': Keycode.INSERT, 'NUMLOCK': Keycode.KEYPAD_NUMLOCK, 'PAGEUP': Keycode.PAGE_UP, |
| 19 | + 'PAGEDOWN': Keycode.PAGE_DOWN, 'PRINTSCREEN': Keycode.PRINT_SCREEN, 'ENTER': Keycode.ENTER, |
| 20 | + 'SCROLLLOCK': Keycode.SCROLL_LOCK, 'SPACE': Keycode.SPACE, 'TAB': Keycode.TAB, |
| 21 | + 'A': Keycode.A, 'B': Keycode.B, 'C': Keycode.C, 'D': Keycode.D, 'E': Keycode.E, |
| 22 | + 'F': Keycode.F, 'G': Keycode.G, 'H': Keycode.H, 'I': Keycode.I, 'J': Keycode.J, |
| 23 | + 'K': Keycode.K, 'L': Keycode.L, 'M': Keycode.M, 'N': Keycode.N, 'O': Keycode.O, |
| 24 | + 'P': Keycode.P, 'Q': Keycode.Q, 'R': Keycode.R, 'S': Keycode.S, 'T': Keycode.T, |
| 25 | + 'U': Keycode.U, 'V': Keycode.V, 'W': Keycode.W, 'X': Keycode.X, 'Y': Keycode.Y, |
| 26 | + 'Z': Keycode.Z, 'F1': Keycode.F1, 'F2': Keycode.F2, 'F3': Keycode.F3, |
| 27 | + 'F4': Keycode.F4, 'F5': Keycode.F5, 'F6': Keycode.F6, 'F7': Keycode.F7, |
| 28 | + 'F8': Keycode.F8, 'F9': Keycode.F9, 'F10': Keycode.F10, 'F11': Keycode.F11, |
| 29 | + 'F12': Keycode.F12, |
| 30 | +} |
27 | 31 |
|
28 | 32 | def convertLine(line):
|
29 |
| - keys = line.split(" ") |
30 | 33 | newline = []
|
31 |
| -# print("keys ", keys) |
32 |
| - |
33 |
| - for k in keys: |
34 |
| - for j in range(len(keycodeCommands)): |
35 |
| - if k == (duckyCommands[j]): |
36 |
| - newline.append(keycodeCommands[j]) |
37 |
| - |
38 |
| -# print("keys commands",newline) |
| 34 | + print(line) |
| 35 | + # loop on each key - the filter removes empty values |
| 36 | + for key in filter(None, line.split(" ")): |
| 37 | + key = key.upper() |
| 38 | + # find the keycode for the command in the list |
| 39 | + command_keycode = duckyCommands.get(key, None) |
| 40 | + if command_keycode is not None: |
| 41 | + # if it exists in the list, use it |
| 42 | + newline.append(command_keycode) |
| 43 | + elif hasattr(Keycode, key): |
| 44 | + # if it's in the Keycode module, use it (allows any valid keycode) |
| 45 | + newline.append(getattr(Keycode, key)) |
| 46 | + else: |
| 47 | + # if it's not a known key name, show the error for diagnosis |
| 48 | + print(f"Unknown key: <{key}>") |
| 49 | + print(newline) |
39 | 50 | return newline
|
40 | 51 |
|
41 | 52 | def runScriptLine(line):
|
|
0 commit comments