def init_window(self): global root self.master.title("LPHK - Novation Launchpad Macro Scripting System") self.pack(fill="both", expand=1) self.m = tk.Menu(self.master) self.master.config(menu=self.m) self.m_Launchpad = tk.Menu(self.m, tearoff=False) self.m_Launchpad.add_command(label="Redetect (Restart)", command=self.redetect_lp) self.m.add_cascade(label="Launchpad", menu=self.m_Launchpad) self.m_Layout = tk.Menu(self.m, tearoff=False) self.m_Layout.add_command(label="New Layout", command=self.unbind_lp) self.m_Layout.add_command(label="Load Layout", command=self.load_layout) self.m_Layout.add_command(label="Save Layout", command=self.save_layout) self.m_Layout.add_command(label="Save Layout As...", command=self.save_layout_as) self.m.add_cascade(label="Layout", menu=self.m_Layout) self.disable_menu("Layout") self.m_Help = tk.Menu(self.m, tearoff=False) open_readme = lambda: webbrowser.open("https://github.com/nimaid/LPHK#lphk-launchpad-hotkey") self.m_Help.add_command(label="Open README...", command=open_readme) open_scripting = lambda: webbrowser.open("https://github.com/nimaid/LPHK#what-is-lphkscript-table-of-contents") self.m_Help.add_command(label="Scripting Help...", command=open_scripting) open_user_folder = lambda: files.open_file_folder(USER_PATH) self.m_Help.add_command(label="User Folder...", command=open_user_folder) open_prog_folder = lambda: files.open_file_folder(PROG_PATH) self.m_Help.add_command(label="Program Folder...", command=open_prog_folder) display_info = lambda: self.popup(self, "About LPHK", self.about_image, "A Novation Launchpad Macro Scripting System\nMade by Ella Jameson (nimaid)\n\nVersion: " + VERSION + "\nFile format version: " + files.FILE_VERSION, "Done") self.m_Help.add_command(label="About LPHK", command=display_info) self.m.add_cascade(label="Help", menu=self.m_Help) c_gap = int(BUTTON_SIZE // 4) c_size = (BUTTON_SIZE * 9) + (c_gap * 9) self.c = tk.Canvas(self, width=c_size, height=c_size) self.c.bind("<Button-1>", self.click) self.c.grid(row=0, column=0, padx=round(c_gap/2), pady=round(c_gap/2)) self.stat = tk.Label(self, text="No Launchpad Connected", bg=STAT_INACTIVE_COLOR, fg="#fff") self.stat.grid(row=1, column=0, sticky=tk.EW) self.stat.config(font=("Courier", BUTTON_SIZE // 3, "bold"))
def main_logic(idx): nonlocal m_pos if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return idx + 1 line = script_lines[idx].strip() if line == "": print("[scripts] " + coords + " Empty line") elif line[0] == "-": print("[scripts] " + coords + " Comment: " + line[1:]) else: split_line = line.split(" ") if split_line[0] == "STRING": type_string = " ".join(split_line[1:]) print("[scripts] " + coords + " Type out string " + type_string) kb.keyboard.write(type_string) elif split_line[0] == "DELAY": print("[scripts] " + coords + " Delay for " + split_line[1] + " seconds") delay = float(split_line[1]) while delay > DELAY_EXIT_CHECK: sleep(DELAY_EXIT_CHECK) delay -= DELAY_EXIT_CHECK if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return -1 if delay > 0: sleep(delay) elif split_line[0] == "TAP": key = kb.sp(split_line[1]) if len(split_line) <= 2: print("[scripts] " + coords + " Tap key " + split_line[1]) kb.tap(key) elif len(split_line) <= 3: print("[scripts] " + coords + " Tap key " + split_line[1] + " " + split_line[2] + " times") taps = int(split_line[2]) for tap in range(taps): if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False kb.release(split_line[1]) threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return idx + 1 kb.tap(key) else: print("[scripts] " + coords + " Tap key " + split_line[1] + " " + split_line[2] + " times for " + str(split_line[3]) + " seconds each") taps = int(split_line[2]) delay = float(split_line[3]) for tap in range(taps): temp_delay = delay if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False kb.release(key) threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return -1 kb.press(key) while temp_delay > DELAY_EXIT_CHECK: sleep(DELAY_EXIT_CHECK) temp_delay -= DELAY_EXIT_CHECK if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False kb.release(key) threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return -1 if temp_delay > 0: sleep(temp_delay) kb.release(key) elif split_line[0] == "PRESS": print("[scripts] " + coords + " Press key " + split_line[1]) key = kb.sp(split_line[1]) kb.press(key) elif split_line[0] == "RELEASE": print("[scripts] " + coords + " Release key " + split_line[1]) key = kb.sp(split_line[1]) kb.release(key) elif split_line[0] == "WEB": link = split_line[1] if "http" not in link: link = "http://" + link print("[scripts] " + coords + " Open website " + link + " in default browser") webbrowser.open(link) elif split_line[0] == "WEB_NEW": link = split_line[1] if "http" not in link: link = "http://" + link print("[scripts] " + coords + " Open website " + link + " in default browser, try to make a new window") webbrowser.open_new(link) elif split_line[0] == "SOUND": if len(split_line) > 2: print("[scripts] " + coords + " Play sound file " + split_line[1] + " at volume " + str(split_line[2])) sound.play(split_line[1], float(split_line[2])) else: print("[scripts] " + coords + " Play sound file " + split_line[1]) sound.play(split_line[1]) elif split_line[0] == "WAIT_UNPRESSED": print("[scripts] " + coords + " Wait for script key to be unpressed") while lp_events.pressed[x][y]: sleep(DELAY_EXIT_CHECK) if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return idx + 1 elif split_line[0] == "M_STORE": print("[scripts] " + coords + " Store mouse position") m_pos = ms.getXY() elif split_line[0] == "M_RECALL": if m_pos == tuple(): print( "[scripts] " + coords + " No 'M_STORE' command has been run, cannot do 'M_RECALL'" ) else: print("[scripts] " + coords + " Recall mouse position " + str(m_pos)) ms.setXY(m_pos[0], m_pos[1]) elif split_line[0] == "M_RECALL_LINE": x1, y1 = m_pos delay = None if len(split_line) > 1: delay = float(split_line[1]) / 1000.0 skip = 1 if len(split_line) > 2: skip = int(split_line[2]) if (delay == None) or (delay <= 0): print("[scripts] " + coords + " Recall mouse position " + str(m_pos) + " in a line by " + str(skip) + " pixels per step") else: print("[scripts] " + coords + " Recall mouse position " + str(m_pos) + " in a line by " + str(skip) + " pixels per step and wait " + split_line[1] + " milliseconds between each step") x_C, y_C = ms.getXY() points = ms.line_coords(x_C, y_C, x1, y1) for x_M, y_M in points[::skip]: if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return -1 ms.setXY(x_M, y_M) if (delay != None) and (delay > 0): temp_delay = delay while temp_delay > DELAY_EXIT_CHECK: sleep(DELAY_EXIT_CHECK) temp_delay -= DELAY_EXIT_CHECK if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return -1 if temp_delay > 0: sleep(temp_delay) elif split_line[0] == "M_MOVE": if len(split_line) >= 3: print("[scripts] " + coords + " Relative mouse movement (" + split_line[1] + ", " + str(split_line[2]) + ")") ms.moveXY(float(split_line[1]), float(split_line[2])) else: print( "[scripts] " + coords + " Both X and Y are required for mouse movement, skipping..." ) elif split_line[0] == "M_SET": if len(split_line) >= 3: print("[scripts] " + coords + " Set mouse position to (" + split_line[1] + ", " + str(split_line[2]) + ")") ms.setXY(float(split_line[1]), float(split_line[2])) else: print( "[scripts] " + coords + " Both X and Y are required for mouse positioning, skipping..." ) elif split_line[0] == "M_SCROLL": if len(split_line) > 2: print("[scripts] " + coords + " Scroll (" + split_line[1] + ", " + split_line[2] + ")") ms.scroll(float(split_line[2]), float(split_line[1])) else: print("[scripts] " + coords + " Scroll " + split_line[1]) ms.scroll(0, float(split_line[1])) elif split_line[0] == "M_LINE": x1 = int(split_line[1]) y1 = int(split_line[2]) x2 = int(split_line[3]) y2 = int(split_line[4]) delay = None if len(split_line) > 5: delay = float(split_line[5]) / 1000.0 skip = 1 if len(split_line) > 6: skip = int(split_line[6]) if (delay == None) or (delay <= 0): print("[scripts] " + coords + " Mouse line from (" + split_line[1] + ", " + split_line[2] + ") to (" + split_line[3] + ", " + split_line[4] + ") by " + str(skip) + " pixels per step") else: print("[scripts] " + coords + " Mouse line from (" + split_line[1] + ", " + split_line[2] + ") to (" + split_line[3] + ", " + split_line[4] + ") by " + str(skip) + " pixels per step and wait " + split_line[5] + " milliseconds between each step") points = ms.line_coords(x1, y1, x2, y2) for x_M, y_M in points[::skip]: if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return -1 ms.setXY(x_M, y_M) if (delay != None) and (delay > 0): temp_delay = delay while temp_delay > DELAY_EXIT_CHECK: sleep(DELAY_EXIT_CHECK) temp_delay -= DELAY_EXIT_CHECK if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return -1 if temp_delay > 0: sleep(temp_delay) elif split_line[0] == "M_LINE_MOVE": x1 = int(split_line[1]) y1 = int(split_line[2]) delay = None if len(split_line) > 3: delay = float(split_line[3]) / 1000.0 skip = 1 if len(split_line) > 4: skip = int(split_line[4]) if (delay == None) or (delay <= 0): print("[scripts] " + coords + " Mouse line move relative (" + split_line[1] + ", " + split_line[2] + ") by " + str(skip) + " pixels per step") else: print("[scripts] " + coords + " Mouse line move relative (" + split_line[1] + ", " + split_line[2] + ") by " + str(skip) + " pixels per step and wait " + split_line[3] + " milliseconds between each step") x_C, y_C = ms.getXY() x_N, y_N = x_C + x1, y_C + y1 points = ms.line_coords(x_C, y_C, x_N, y_N) for x_M, y_M in points[::skip]: if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return -1 ms.setXY(x_M, y_M) if (delay != None) and (delay > 0): temp_delay = delay while temp_delay > DELAY_EXIT_CHECK: sleep(DELAY_EXIT_CHECK) temp_delay -= DELAY_EXIT_CHECK if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return -1 if temp_delay > 0: sleep(temp_delay) elif split_line[0] == "M_LINE_SET": x1 = int(split_line[1]) y1 = int(split_line[2]) delay = None if len(split_line) > 3: delay = float(split_line[3]) / 1000.0 skip = 1 if len(split_line) > 4: skip = int(split_line[4]) if (delay == None) or (delay <= 0): print("[scripts] " + coords + " Mouse line set (" + split_line[1] + ", " + split_line[2] + ") by " + str(skip) + " pixels per step") else: print("[scripts] " + coords + " Mouse line set (" + split_line[1] + ", " + split_line[2] + ") by " + str(skip) + " pixels per step and wait " + split_line[3] + " milliseconds between each step") x_C, y_C = ms.getXY() points = ms.line_coords(x_C, y_C, x1, y1) for x_M, y_M in points[::skip]: if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return -1 ms.setXY(x_M, y_M) if (delay != None) and (delay > 0): temp_delay = delay while temp_delay > DELAY_EXIT_CHECK: sleep(DELAY_EXIT_CHECK) temp_delay -= DELAY_EXIT_CHECK if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return -1 if temp_delay > 0: sleep(temp_delay) elif split_line[0] == "LABEL": print("[scripts] " + coords + " Label: " + split_line[1]) return idx + 1 elif split_line[0] == "IF_PRESSED_GOTO_LABEL": print("[scripts] " + coords + " If key is pressed goto LABEL " + split_line[1]) if lp_events.pressed[x][y]: return labels[split_line[1]] elif split_line[0] == "IF_UNPRESSED_GOTO_LABEL": print("[scripts] " + coords + " If key is not pressed goto LABEL " + split_line[1]) if not lp_events.pressed[x][y]: return labels[split_line[1]] elif split_line[0] == "GOTO_LABEL": print("[scripts] " + coords + " Goto LABEL " + split_line[1]) return labels[split_line[1]] elif split_line[0] == "REPEAT_LABEL": print("[scripts] " + coords + " Repeat LABEL " + split_line[1] + " " + split_line[2] + " times max") if idx in repeats: if repeats[idx] > 0: print("[scripts] " + coords + " " + str(repeats[idx]) + " repeats left.") repeats[idx] -= 1 return labels[split_line[1]] else: print("[scripts] " + coords + " No repeats left, not repeating.") else: repeats[idx] = int(split_line[2]) repeats_original[idx] = int(split_line[2]) print("[scripts] " + coords + " " + str(repeats[idx]) + " repeats left.") repeats[idx] -= 1 return labels[split_line[1]] elif split_line[0] == "IF_PRESSED_REPEAT_LABEL": print("[scripts] " + coords + " If key is pressed repeat LABEL " + split_line[1] + " " + split_line[2] + " times max") if lp_events.pressed[x][y]: if idx in repeats: if repeats[idx] > 0: print("[scripts] " + coords + " " + str(repeats[idx]) + " repeats left.") repeats[idx] -= 1 return labels[split_line[1]] else: print("[scripts] " + coords + " No repeats left, not repeating.") else: repeats[idx] = int(split_line[2]) print("[scripts] " + coords + " " + str(repeats[idx]) + " repeats left.") repeats[idx] -= 1 return labels[split_line[1]] elif split_line[0] == "IF_UNPRESSED_REPEAT_LABEL": print("[scripts] " + coords + " If key is not pressed repeat LABEL " + split_line[1] + " " + split_line[2] + " times max") if not lp_events.pressed[x][y]: if idx in repeats: if repeats[idx] > 0: print("[scripts] " + coords + " " + str(repeats[idx]) + " repeats left.") repeats[idx] -= 1 return labels[split_line[1]] else: print("[scripts] " + coords + " No repeats left, not repeating.") else: repeats[idx] = int(split_line[2]) print("[scripts] " + coords + " " + str(repeats[idx]) + " repeats left.") repeats[idx] -= 1 return labels[split_line[1]] elif split_line[0] == "@SIMPLE": print("[scripts] " + coords + " Simple keybind: " + split_line[1]) #PRESS key = kb.sp(split_line[1]) kb.press(key) #WAIT_UNPRESSED while lp_events.pressed[x][y]: sleep(DELAY_EXIT_CHECK) if threads[x][y].kill.is_set(): print("[scripts] " + coords + " Recieved exit flag, script exiting...") threads[x][y].kill.clear() if not is_async: running = False threading.Timer(EXIT_UPDATE_DELAY, lp_colors.updateXY, (x, y)).start() return idx + 1 #RELEASE kb.release(key) elif split_line[0] == "OPEN": path_name = " ".join(split_line[1:]) print("[scripts] " + coords + " Open file or folder " + path_name) files.open_file_folder(path_name) elif split_line[0] == "RELEASE_ALL": print("[scripts] " + coords + " Release all keys") kb.release_all() elif split_line[0] == "RESET_REPEATS": print("[scripts] " + coords + " Reset all repeats") for i in repeats: repeats[i] = repeats_original[i] else: print("[scripts] " + coords + " Invalid command: " + split_line[0] + ", skipping...") return idx + 1
def main_logic(idx): nonlocal m_pos if check_kill(x, y, is_async): return idx + 1 line = script_lines[idx] if line == "": return idx + 1 if line[0] == "-": print("[scripts] " + coords + " Comment: " + line[1:]) else: split_line = line.split(" ") if split_line[0] == "STRING": type_string = " ".join(split_line[1:]) print("[scripts] " + coords + " Type out string " + type_string) kb.write(type_string) elif split_line[0] == "DELAY": print("[scripts] " + coords + " Delay for " + split_line[1] + " seconds") delay = float(split_line[1]) if not safe_sleep(delay, x, y, is_async): return -1 elif split_line[0] == "TAP": key = kb.sp(split_line[1]) releasefunc = lambda: kb.release(key) if len(split_line) <= 2: print("[scripts] " + coords + " Tap key " + split_line[1]) kb.tap(key) elif len(split_line) <= 3: print("[scripts] " + coords + " Tap key " + split_line[1] + " " + split_line[2] + " times") taps = int(split_line[2]) for tap in range(taps): if check_kill(x, y, is_async, releasefunc): return idx + 1 kb.tap(key) else: print("[scripts] " + coords + " Tap key " + split_line[1] + " " + split_line[2] + " times for " + str(split_line[3]) + " seconds each") taps = int(split_line[2]) delay = float(split_line[3]) for tap in range(taps): if check_kill(x, y, is_async, releasefunc): return -1 kb.press(key) if not safe_sleep(delay, x, y, is_async, releasefunc): return -1 elif split_line[0] == "PRESS": print("[scripts] " + coords + " Press key " + split_line[1]) key = kb.sp(split_line[1]) kb.press(key) elif split_line[0] == "RELEASE": print("[scripts] " + coords + " Release key " + split_line[1]) key = kb.sp(split_line[1]) kb.release(key) elif split_line[0] == "WEB": link = split_line[1] if "http" not in link: link = "http://" + link print("[scripts] " + coords + " Open website " + link + " in default browser") webbrowser.open(link) elif split_line[0] == "WEB_NEW": link = split_line[1] if "http" not in link: link = "http://" + link print("[scripts] " + coords + " Open website " + link + " in default browser, try to make a new window") webbrowser.open_new(link) elif split_line[0] == "CODE": args = " ".join(split_line[1:]) print("[scripts] " + coords + " Running code: " + args) try: subprocess.run(args) except Exception as e: print("[scripts] " + coords + " Error with running code: " + str(e)) elif split_line[0] == "SOUND": if len(split_line) > 2: print("[scripts] " + coords + " Play sound file " + split_line[1] + " at volume " + str(split_line[2])) sound.play(split_line[1], float(split_line[2])) else: print("[scripts] " + coords + " Play sound file " + split_line[1]) sound.play(split_line[1]) elif split_line[0] == "WAIT_UNPRESSED": print("[scripts] " + coords + " Wait for script key to be unpressed") while lp_events.pressed[x][y]: sleep(DELAY_EXIT_CHECK) if check_kill(x, y, is_async): return idx + 1 elif split_line[0] == "M_STORE": print("[scripts] " + coords + " Store mouse position") m_pos = ms.get_pos() elif split_line[0] == "M_RECALL": if m_pos == tuple(): print( "[scripts] " + coords + " No 'M_STORE' command has been run, cannot do 'M_RECALL'" ) else: print("[scripts] " + coords + " Recall mouse position " + str(m_pos)) ms.set_pos(m_pos[0], m_pos[1]) elif split_line[0] == "M_RECALL_LINE": x1, y1 = m_pos delay = None if len(split_line) > 1: delay = float(split_line[1]) / 1000.0 skip = 1 if len(split_line) > 2: skip = int(split_line[2]) if (delay == None) or (delay <= 0): print("[scripts] " + coords + " Recall mouse position " + str(m_pos) + " in a line by " + str(skip) + " pixels per step") else: print("[scripts] " + coords + " Recall mouse position " + str(m_pos) + " in a line by " + str(skip) + " pixels per step and wait " + split_line[1] + " milliseconds between each step") x_C, y_C = ms.get_pos() points = ms.line_coords(x_C, y_C, x1, y1) for x_M, y_M in points[::skip]: if check_kill(x, y, is_async): return -1 ms.set_pos(x_M, y_M) if (delay != None) and (delay > 0): if not safe_sleep(delay, x, y, is_async): return -1 elif split_line[0] == "M_MOVE": if len(split_line) >= 3: print("[scripts] " + coords + " Relative mouse movement (" + split_line[1] + ", " + str(split_line[2]) + ")") ms.move_to_pos(float(split_line[1]), float(split_line[2])) else: print( "[scripts] " + coords + " Both X and Y are required for mouse movement, skipping..." ) elif split_line[0] == "M_SET": if len(split_line) >= 3: print("[scripts] " + coords + " Set mouse position to (" + split_line[1] + ", " + str(split_line[2]) + ")") ms.set_pos(float(split_line[1]), float(split_line[2])) else: print( "[scripts] " + coords + " Both X and Y are required for mouse positioning, skipping..." ) elif split_line[0] == "M_SCROLL": if len(split_line) > 2: print("[scripts] " + coords + " Scroll (" + split_line[1] + ", " + split_line[2] + ")") ms.scroll(float(split_line[2]), float(split_line[1])) else: print("[scripts] " + coords + " Scroll " + split_line[1]) ms.scroll(0, float(split_line[1])) elif split_line[0] == "M_LINE": x1 = int(split_line[1]) y1 = int(split_line[2]) x2 = int(split_line[3]) y2 = int(split_line[4]) delay = None if len(split_line) > 5: delay = float(split_line[5]) / 1000.0 skip = 1 if len(split_line) > 6: skip = int(split_line[6]) if (delay == None) or (delay <= 0): print("[scripts] " + coords + " Mouse line from (" + split_line[1] + ", " + split_line[2] + ") to (" + split_line[3] + ", " + split_line[4] + ") by " + str(skip) + " pixels per step") else: print("[scripts] " + coords + " Mouse line from (" + split_line[1] + ", " + split_line[2] + ") to (" + split_line[3] + ", " + split_line[4] + ") by " + str(skip) + " pixels per step and wait " + split_line[5] + " milliseconds between each step") points = ms.line_coords(x1, y1, x2, y2) for x_M, y_M in points[::skip]: if check_kill(x, y, is_async): return -1 ms.set_pos(x_M, y_M) if (delay != None) and (delay > 0): if not safe_sleep(delay, x, y, is_async): return -1 elif split_line[0] == "M_LINE_MOVE": x1 = int(split_line[1]) y1 = int(split_line[2]) delay = None if len(split_line) > 3: delay = float(split_line[3]) / 1000.0 skip = 1 if len(split_line) > 4: skip = int(split_line[4]) if (delay == None) or (delay <= 0): print("[scripts] " + coords + " Mouse line move relative (" + split_line[1] + ", " + split_line[2] + ") by " + str(skip) + " pixels per step") else: print("[scripts] " + coords + " Mouse line move relative (" + split_line[1] + ", " + split_line[2] + ") by " + str(skip) + " pixels per step and wait " + split_line[3] + " milliseconds between each step") x_C, y_C = ms.get_pos() x_N, y_N = x_C + x1, y_C + y1 points = ms.line_coords(x_C, y_C, x_N, y_N) for x_M, y_M in points[::skip]: if check_kill(x, y, is_async): return -1 ms.set_pos(x_M, y_M) if (delay != None) and (delay > 0): if not safe_sleep(delay, x, y, is_async): return -1 elif split_line[0] == "M_LINE_SET": x1 = int(split_line[1]) y1 = int(split_line[2]) delay = None if len(split_line) > 3: delay = float(split_line[3]) / 1000.0 skip = 1 if len(split_line) > 4: skip = int(split_line[4]) if (delay == None) or (delay <= 0): print("[scripts] " + coords + " Mouse line set (" + split_line[1] + ", " + split_line[2] + ") by " + str(skip) + " pixels per step") else: print("[scripts] " + coords + " Mouse line set (" + split_line[1] + ", " + split_line[2] + ") by " + str(skip) + " pixels per step and wait " + split_line[3] + " milliseconds between each step") x_C, y_C = ms.get_pos() points = ms.line_coords(x_C, y_C, x1, y1) for x_M, y_M in points[::skip]: if check_kill(x, y, is_async): return -1 ms.set_pos(x_M, y_M) if (delay != None) and (delay > 0): if not safe_sleep(delay, x, y, is_async): return -1 elif split_line[0] == "LABEL": print("[scripts] " + coords + " Label: " + split_line[1]) return idx + 1 elif split_line[0] == "IF_PRESSED_GOTO_LABEL": print("[scripts] " + coords + " If key is pressed goto LABEL " + split_line[1]) if lp_events.pressed[x][y]: return labels[split_line[1]] elif split_line[0] == "IF_UNPRESSED_GOTO_LABEL": print("[scripts] " + coords + " If key is not pressed goto LABEL " + split_line[1]) if not lp_events.pressed[x][y]: return labels[split_line[1]] elif split_line[0] == "GOTO_LABEL": print("[scripts] " + coords + " Goto LABEL " + split_line[1]) return labels[split_line[1]] elif split_line[0] == "REPEAT_LABEL": print("[scripts] " + coords + " Repeat LABEL " + split_line[1] + " " + split_line[2] + " times max") if idx in repeats: if repeats[idx] > 0: print("[scripts] " + coords + " " + str(repeats[idx]) + " repeats left.") repeats[idx] -= 1 return labels[split_line[1]] else: print("[scripts] " + coords + " No repeats left, not repeating.") else: repeats[idx] = int(split_line[2]) repeats_original[idx] = int(split_line[2]) print("[scripts] " + coords + " " + str(repeats[idx]) + " repeats left.") repeats[idx] -= 1 return labels[split_line[1]] elif split_line[0] == "IF_PRESSED_REPEAT_LABEL": print("[scripts] " + coords + " If key is pressed repeat LABEL " + split_line[1] + " " + split_line[2] + " times max") if lp_events.pressed[x][y]: if idx in repeats: if repeats[idx] > 0: print("[scripts] " + coords + " " + str(repeats[idx]) + " repeats left.") repeats[idx] -= 1 return labels[split_line[1]] else: print( "[scripts] " + coords + " No repeats left, not repeating.") else: repeats[idx] = int(split_line[2]) print("[scripts] " + coords + " " + str(repeats[idx]) + " repeats left.") repeats[idx] -= 1 return labels[split_line[1]] elif split_line[0] == "IF_UNPRESSED_REPEAT_LABEL": print("[scripts] " + coords + " If key is not pressed repeat LABEL " + split_line[1] + " " + split_line[2] + " times max") if not lp_events.pressed[x][y]: if idx in repeats: if repeats[idx] > 0: print("[scripts] " + coords + " " + str(repeats[idx]) + " repeats left.") repeats[idx] -= 1 return labels[split_line[1]] else: print( "[scripts] " + coords + " No repeats left, not repeating.") else: repeats[idx] = int(split_line[2]) print("[scripts] " + coords + " " + str(repeats[idx]) + " repeats left.") repeats[idx] -= 1 return labels[split_line[1]] elif split_line[0] == "@SIMPLE": print("[scripts] " + coords + " Simple keybind: " + split_line[1]) #PRESS key = kb.sp(split_line[1]) releasefunc = lambda: kb.release(key) kb.press(key) #WAIT_UNPRESSED while lp_events.pressed[x][y]: sleep(DELAY_EXIT_CHECK) if check_kill(x, y, is_async, releasefunc): return idx + 1 #RELEASE kb.release(key) elif split_line[0] == "@LOAD_LAYOUT": layout_name = " ".join(split_line[1:]) print("[scripts] " + coords + " Load layout " + layout_name) layout_path = os.path.join(files.LAYOUT_PATH, layout_name) if not os.path.isfile(layout_path): print("[scripts] " + coords + " ERROR: Layout file does not exist.") return -1 try: layout = files.load_layout(layout_path, popups=False, save_converted=False) except files.json.decoder.JSONDecodeError: print("[scripts] " + coords + " ERROR: Layout is malformated.") return -1 if files.layout_changed_since_load: files.save_lp_to_layout(files.curr_layout) files.load_layout_to_lp(layout_path, popups=False, save_converted=False, preload=layout) elif split_line[0] == "OPEN": path_name = " ".join(split_line[1:]) print("[scripts] " + coords + " Open file or folder " + path_name) files.open_file_folder(path_name) elif split_line[0] == "RELEASE_ALL": print("[scripts] " + coords + " Release all keys") kb.release_all() elif split_line[0] == "RESET_REPEATS": print("[scripts] " + coords + " Reset all repeats") for i in repeats: repeats[i] = repeats_original[i] else: print("[scripts] " + coords + " Invalid command: " + split_line[0] + ", skipping...") return idx + 1