boppreh / keyboard

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

add_hotkey doesn't seem to work #607

Closed its-mrarsikk closed 1 year ago

its-mrarsikk commented 1 year ago

Hello. I have this script:

import os
import sys
import keyboard

print('Hello World!')

keyboard.add_hotkey('ctrl+shift+a', lambda: print('à'))

And the invoking code:

with open('./out.log', 'w') as log:
    return subprocess.Popen(['sudo', 'python3', './platform/unix/keycatcher.py'], stdout=log, stderr=log) # keycatcher.py is the script

The issue is: nothing was written to out.log except “Hello World!”. The app was exiting after a few seconds, but even if I hit the hotkey while it's running, nothing gets written. Then, I modified the code:

import os
import sys
import keyboard

print('Hello World!')

keyboard.add_hotkey('ctrl+shift+a', lambda: print('à'))

keyboard.wait()

But now, even Hello World doesn't get written. out.log is just empty.

Is this a module issue, or am i doing something wrong?