Keyboard bind detection priority

17 Views Asked by At

I have created a script that listens to the keyboard if keyboard.is_pressed(key) and performs some action (now just typing text). The program works, but for example when I use this in notepad (with alt+1 bind) sometimes it works sometimes it doesn't.
Does anyone know of solutions to give the highest priority to my bind? I want the combination to be ctrl-left or alt-left, which generates problems.

t_pressed = tde_pressed = teng_pressed = False
    last_activation_time = 0
    debounce_delay = 0.3  # 

    while should_continue:
        current_time = time.time()
        
        if Key_1_translate and Key_2_translate:
            if keyboard.is_pressed(Key_1) and keyboard.is_pressed(Key_2):
                if not t_pressed and current_time - last_activation_time > debounce_delay:
                    copy_and_print() #a function that does something
                    t_pressed = True
                    last_activation_time = current_time
            else:
                t_pressed = False

When the program is reset, it works properly again. Most problems occur when the active window also uses function keys.

0

There are 0 best solutions below