[Python] keyboard.add_hotkey stops working after opening taskmanager

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using the python module keyboard to create a hotkey, and it works like its supposed to until I open task manager, after that the hotkey just stops working, creating a new one doesn't help, no hotkeys work after task manager gets opened.

    import keyboard

    def hello():
    print('hello world!')

    keyboard.add_hotkey('alt+p', hello, args=())

    while True:
    pass


    the above code is just an example to replicate the issue, i import the module, create a hotkey, then create a infinite while loop so the program doesn't exit, and the hotkey works until you open task manager.

    The reason for why I need to use add_hotkey and not any other function is because Im going to use it for a much larger program, and add_hotkey doesn't slow the app down, but of course, it can break and then only a restart of the program will fix it.

    I have tried a lot of stuff already, that have partially worked, re-importing the module works great, but I dont have a way of knowing the right time of re-importing it, and I could also run the program as admin, that solves the issue as well, but I don't want the program to be ran as admin only because of a hotkey function.

    Continue reading...

Compartilhe esta Página