boppreh / keyboard

Hook and simulate global keyboard events on Windows and Linux.
MIT License
3.76k stars 433 forks source link

when using the hotkey, do you need a constant loop to check for it? #594

Open CyberYoda05 opened 1 year ago

CoreTaxxe commented 1 year ago

No, but you need to keep the program running.

keyboard.add_hotkey("m",lambda : print("M pressed"))

while True:
    time.sleep(10000)     # -> without this it will simply close the program.

this works as well

keyboard.add_hotkey("m",lambda : print("M pressed"))

time.sleep(1000)     # -> now the program will stop after 1000 seconds