Пример #1
0
def unbind_all():
    global press_funcs
    press_funcs = [[unbound_press for y in range(9)] for x in range(9)]
    for x in range(9):
        for y in range(9):
            lp_colors.setXY(x, y, lp_colors.BLACK)
    lp_colors.raw_clear()
Пример #2
0
def load_layout(name, add_path=True):
    global curr_layout
    scripts.unbind_all()

    final_path = None
    if add_path:
        final_path = PATH + LAYOUT_PATH + name + LAYOUT_EXT
    else:
        final_path = name
    with open(final_path, "r") as f:
        l = f.readlines()

        for x in range(9):
            line = l[x][:-1].split(BUTTON_SEPERATOR)
            for y in range(9):
                info = line[y].split(ENTRY_SEPERATOR)
                color = int(info[0])
                script_text = info[1].replace(NEWLINE_REPLACE, "\n")

                if script_text != "":
                    scripts.bind(x, y, script_text, color)
                else:
                    lp_colors.setXY(x, y, color)
        lp_colors.update_all()
    curr_layout = final_path
    print("[files] Loaded layout " + final_path)
Пример #3
0
def load_layout_to_lp(name, popups=True, save_converted=True, preload=None):
    global curr_layout
    global in_error
    global layout_changed_since_load
    
    converted_to_rg = False
    
    scripts.unbind_all()
    window.app.draw_canvas()
    
    if preload == None:
        layout = load_layout(name, popups=popups, save_converted=save_converted)
    else:
        layout = preload
        
    for x in range(9):
        for y in range(9):
            button = layout["buttons"][x][y]
            color = button["color"]
            script_text = button["text"]
        
            if window.lp_mode == "Mk1":
                if color[2] != 0:
                    color = lp_colors.RGB_to_RG(color)
                    converted_to_rg = True
            
            if script_text != "":
                script_validation = None
                try:
                    script_validation = scripts.validate_script(script_text)
                except:
                    new_layout_func = lambda: window.app.unbind_lp(prompt_save = False)
                    if popups:
                        window.app.popup(window.app, "Script Validation Error", window.app.error_image, "Fatal error while attempting to validate script.\nPlease see LPHK.log for more information.", "OK", end_command = new_layout_func)
                    else:
                        print("[files] Fatal error while attempting to validate script.\nPlease see LPHK.log for more information.")
                    raise
                if script_validation != True:
                    lp_colors.update_all()
                    window.app.draw_canvas()
                    in_error = True
                    window.app.save_script(window.app, x, y, script_text, open_editor = True, color = color)
                    in_error = False
                else:
                    scripts.bind(x, y, script_text, color)
            else:
                lp_colors.setXY(x, y, color)
    lp_colors.update_all()
    window.app.draw_canvas()
        
    curr_layout = name
    if converted_to_rg:
        if popups:
            window.app.popup(window.app, "Layout converted to Classic/Mini/S...", window.app.info_image, "The colors in this layout have been converted to be\ncompatable with the Launchpad Classic/Mini/S.\n\nChanges have not yet been saved to the file.", "OK")
        else:
            print("[files] The colors in this layout have been converted to be compatable with the Launchpad Classic/Mini/S. Changes have not yet been saved to the file.")
        layout_changed_since_load = True
    else:
        layout_changed_since_load = False
Пример #4
0
def unbind_all(update_colors=True):
    global press_funcs
    global release_funcs
    press_funcs = [[unbound_press for y in range(9)] for x in range(9)]
    release_funcs = [[unbound_release for y in range(9)] for x in range(9)]
    for x in range(9):
        for y in range(9):
            lp_colors.setXY(x, y, lp_colors.BLACK)
            lp_colors.effectXY(x, y, lp_colors.BLACK)
    if update_colors:
        lp_colors.update()
Пример #5
0
def bind_func_with_colors(x,
                          y,
                          func,
                          off_color,
                          on_color=lp_colors.GREEN,
                          release_func=None):
    global press_funcs
    if release_func == None:
        release_func = lambda a, b: None
    press_funcs[x][y] = func
    release_funcs[x][y] = release_func
    lp_colors.setXY(x, y, off_color)
    lp_colors.effectXY(x, y, on_color)
Пример #6
0
def load_layout(name, add_path=True):
    global curr_layout
    global in_error
    global layout_changed_since_load
    
    scripts.unbind_all()
    window.app.draw_canvas()
    
    final_path = None
    if add_path:
        final_path = PATH + LAYOUT_PATH + name + LAYOUT_EXT
    else:
        final_path = name
    with open(final_path, "r") as f:
        l = f.readlines()

        for x in range(9):
            line = l[x][:-1].split(BUTTON_SEPERATOR)
            for y in range(9):
                info = line[y].split(ENTRY_SEPERATOR)
                color = info[0]
                if not color.isdigit():
                    split = color.split(",")
                    color = []
                    color.append(int(split[0]))
                    color.append(int(split[1]))
                    color.append(int(split[2]))
                else:
                    color = int(info[0])
                script_text = info[1].replace(NEWLINE_REPLACE, "\n")

                if script_text != "":
                    script_validation = scripts.validate_script(script_text)
                    if script_validation != True:
                        lp_colors.update_all()
                        window.app.draw_canvas()
                        in_error = True
                        window.app.save_script(window.app, x, y, script_text, open_editor = True, color = color)
                        in_error = False
                    else:
                        scripts.bind(x, y, script_text, color)
                else:
                    lp_colors.setXY(x, y, color)
        lp_colors.update_all()
        window.app.draw_canvas()
    curr_layout = final_path
    layout_changed_since_load = False
    print("[files] Loaded layout " + final_path)
Пример #7
0
def bind_grid():
    init()

    for y in range(1, 9):
        for x in range(8):
            note = working_notes[y-1][x]

            if note % 12 == base_note % 12:
                lp_colors.setXY(x, y, COLOR_ROOT)
            elif note % 12 in [n%12 for n in working_scale]:
                lp_colors.setXY(x, y, COLOR_SCALE)
            else:
                lp_colors.setXY(x, y, COLOR_DEFAULT)

            if lp_events.pressed[x][y]:
                if lp_scaleedit.is_active:
                    curr_note = working_notes[y-1][x]
                    #bind the release to a func that: updates colors, rebinds to correct note
                    lp_events.release_funcs[x][y] = functools.partial(off_note_and_rebind_new_note, old_note=None, new_note=curr_note, off_note=False)
                else:
                    prev_note = lp_midi.note_when_pressed[x][y]
                    lp_events.release_funcs[x][y] = functools.partial(off_note_and_rebind_new_note, old_note=prev_note, new_note=note)
            else:
                lp_midi.bind_button_to_note(x, y, note)
Пример #8
0
def load_layout_to_lp(name, popups=True, save_converted=True, preload=None):
    global curr_layout
    global in_error
    global layout_changed_since_load

    converted_to_rg = False

    scripts.Unbind_all()
    scripts.Unload_all()                         # remove all existing subroutines when you load a new layout
    window.Redraw(True)

    if preload == None:
        layout = load_layout(name, popups=popups, save_converted=save_converted)
    else:
        layout = preload

    # load subroutines before buttons so you don't get errors on buttons using them
    if "subroutines" in layout:                  # were subroutines saved?
        for sub in layout["subroutines"]:        # for all the subroutines that were saved
            load_subroutine(sub, 0, 'LAYOUT')    # load the subroutine

    for x in range(9):
        for y in range(9):
            button = layout["buttons"][x][y]
            color = button["color"]
            script_text = button["text"]

            if window.lp_mode == LP_MK1:
                if color[2] != 0:
                    color = lp_colors.RGB_to_RG(color)
                    converted_to_rg = True

            if script_text != "":
                script_validation = None
                try:
                    btn = scripts.Button(x, y, script_text)
                    script_validation = btn.Validate_script()
                except:
                    new_layout_func = lambda: window.app.unbind_lp(prompt_save = False)
                    if popups:
                        window.app.popup(window.app, "Script Validation Error", window.app.error_image, "Fatal error while attempting to validate script.\nPlease see LPHK.log for more information.", "OK", end_command = new_layout_func)
                    else:
                        print("[files] Fatal error while attempting to validate script.\nPlease see LPHK.log for more information.")
                    raise
                if script_validation != True:
                    lp_colors.update_all()
                    window.Redraw(True)
                    in_error = True
                    window.app.save_script(window.app, x, y, script_text, open_editor = True, color = color)
                    in_error = False
                else:
                    scripts.Bind(x, y, btn, color)
            else:
                lp_colors.setXY(x, y, color)

    lp_colors.update_all()
    window.Redraw(True)

    curr_layout = name
    if converted_to_rg:
        if popups:
            window.app.popup(window.app, "Layout converted to Classic/Mini/S...", window.app.info_image, "The colors in this layout have been converted to be\ncompatable with the Launchpad Classic/Mini/S.\n\nChanges have not yet been saved to the file.", "OK")
        else:
            print("[files] The colors in this layout have been converted to be compatable with the Launchpad Classic/Mini/S. Changes have not yet been saved to the file.")
        layout_changed_since_load = True
    else:
        layout_changed_since_load = False
Пример #9
0
def unbind(x, y):
    global press_funcs
    press_funcs[x][y] = unbound_press
    lp_colors.setXY(x, y, lp_colors.BLACK)
    lp_colors.updateXY(x, y)
Пример #10
0
def bind_func_with_colors(x, y, func, off_color):
    global press_funcs
    press_funcs[x][y] = func
    lp_colors.setXY(x, y, off_color)
Пример #11
0
    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]
            elif split_line[0] == "LOAD_LAYOUT":
                files.load_layout(split_line[1])
            elif split_line[0] == "SET_COLOR":
                color = split_line[1]
                try:
                    color = int(color)
                except:
                    color = color.split(",")
                    if len(color) != 3:
                        print("[scripts] " + coords + "    Invalid color for command SET_COLOR")
                        return idx + 1
                    try:
                        color = [int(color[0]), int(color[1]), int(color[2])]
                    except:
                        print("[scripts] " + coords + "    Invalid color for command SET_COLOR")
                        return idx + 1
                    if color[0] > 50 or color[1] > 50 or color[2] > 50:
                        print("[scripts] " + coords + "    Invalid color for command SET_COLOR")
                        return idx + 1
                finally:
                    x1 = x
                    y1 = y
                    if len(split_line) > 3:
                        x1 = int(split_line[2])
                        x2 = int(split_line[3])
                    lp_colors.setXY(x1, y1, color, "solid")
                    lp_colors.updateXY(x1, y1)
            elif split_line[0] == "TOGGLE":
                new = not toggles[x][y]
                if len(split_line) > 1:
                    new = split_line[1] == "on"
                toggles[x][y] = new
            elif split_line[0] == "IF_TOGGLED_GOTO_LABEL":
                if toggles[x][y]:
                    return labels[split_line[1]]
            elif split_line[0] == "EXIT":
                return -1
            elif split_line[0] == "SELECT_WINDOW":
                windows.select_window(split_line[1])
            elif split_line[0] == "SET_COLOR_MODE":
                try:
                    color = int(split_line[1])
                except:
                    print("[scripts] " + coords + "    Invalid color for command SET_COLOR_MODE")
                    return idx + 1
                if color > 50:
                    print("[scripts] " + coords + "    Invalid color for command SET_COLOR_MODE")
                    return idx + 1
                mode = split_line[2]
                if mode != "solid" and mode != "flash" and mode != "pulse":
                    print("[scripts] " + coords + "    Invalid mode for command SET_COLOR_MODE")
                    return idx + 1
                x1 = x
                y1 = y
                if len(split_line) > 4:
                    x1 = int(split_line[3])
                    x2 = int(split_line[4])
                lp_colors.setXY(x1, y1, color, mode)
                lp_colors.updateXY(x1, y1)
            else:
                print("[scripts] " + coords + "    Invalid command: " + split_line[0] + ", skipping...")
        return idx + 1