moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.73k stars 243 forks source link

hotkeys unrelease bug #576

Closed wzzb521 closed 8 months ago

wzzb521 commented 9 months ago

Description When on_activate func is blocked and takes more than 2 seconds,the hotkeys will not release successfully. Next time you press the hotkeys will release them only, and the on_activate func will not be activated as expected.

Platform and pynput version win10 22h2 python 3.10.6 pynput 1.7.6

To Reproduce

import time
from pynput import keyboard as kb

def hk_unrelease_bug():
    def on_active_e():
        sys.exit(0)

    def foo():
        print("I'm sleeping")
        time.sleep(3)
        print("awake")

    with kb.GlobalHotKeys({
        '<ctrl>+e': on_active_e,
        'q+w+e': foo
    }) as hk:
        hk.join()

hk_unrelease_bug()
moses-palmer commented 8 months ago

Thank you for your comment,

Please consult the documentation regarding blocking event handlers.