I want to bind hot-keys to function in the python code, so I installed keybind
, but the error occurs. How to fix it?
The code is
from keybind import KeyBinder
import time
def pr():
print('yeh')
KeyBinder.activate({'Ctrl-C': pr}, run_thread = True)
while True:
print(1)
time.sleep(1)
Then the error is
Traceback (most recent call last):
File "C:\Users\Idensas\PycharmProjects\protest\ZEMPTY.py", line 6, in <module>
KeyBinder.activate({'Ctrl-C':pr},run_thread=True)
File "C:\Users\Idensas\AppData\Local\Programs\Python\Python39\lib\site-packages\keybind\binder.py", line 85, in activate
binder = cls(keymap=keymap, listen_events=listen_events)
File "C:\Users\Idensas\AppData\Local\Programs\Python\Python39\lib\site- packages\keybind\binder.py", line 63, in __init__
self.disp = Display()
File "C:\Users\Idensas\AppData\Local\Programs\Python\Python39\lib\site-packages\Xlib\display.py", line 89, in __init__
self.display = _BaseDisplay(display)
File "C:\Users\Idensas\AppData\Local\Programs\Python\Python39\lib\site-packages\Xlib\display.py", line 71, in __init__
protocol_display.Display.__init__(self, *args, **keys)
File "C:\Users\Idensas\AppData\Local\Programs\Python\Python39\lib\site- packages\Xlib\protocol\display.py", line 84, in __init__
name, protocol, host, displayno, screenno = connect.get_display(display)
File "C:\Users\Idensas\AppData\Local\Programs\Python\Python39\lib\site- packages\Xlib\support\connect.py", line 72, in get_display
mod = _relative_import(modname)
File "C:\Users\Idensas\AppData\Local\Programs\Python\Python39\lib\site- packages\Xlib\support\connect.py", line 55, in _relative_import
return importlib.import_module('..' modname, __name__)
File "C:\Users\Idensas\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\Idensas\AppData\Local\Programs\Python\Python39\lib\site- packages\Xlib\support\unix_connect.py", line 31, in <module>
import fcntl
ModuleNotFoundError: No module named 'fcntl'
CodePudding user response:
fcntl
is a mechanism on Linux, not Windows systems.
From the keybind
docs:
Requires X11 (X Window System). For UNIX-like systems, e.g. Linux.
https://pypi.org/project/keybind/
You will therefore need a different library for Windows systems.