我有一个在 python3.4 上运行的 python 脚本,并使用该包keyboard来允许按键绑定;
keyboard.add_hotkey("enter", self.listener.stop, suppress=True)
keyboard.add_hotkey("shift+enter", self.listener.finish, suppress=True)
Run Code Online (Sandbox Code Playgroud)
当我在 Windows 上运行它时,它可以完美地监听两个热键,当在 Linux (CentOS) 上运行时它也可以工作。
在工作中,我通过 Windows 10 功能和应用商店在 Windows 上获得了 Ubuntu 环境。但是这个环境下这个键盘热键有问题。
/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/_nixkeyboard.py:110: UserWarning: Failed to create a device file using `uinput` module. Sending of events may be limited or unavailable depending on plugged-in devices.
device = aggregate_devices('kbd')
Traceback (most recent call last):
File "main.py", line 32, in <module>
], 'test')
File "/mnt/.../can_controller.py", line 28, in __init__
self.__initialise_key_handler()
File "/mnt/.../can_controller.py", line 95, in __initialise_key_handler
keyboard.add_hotkey("enter", …Run Code Online (Sandbox Code Playgroud) keyboard ubuntu python-3.x uinput windows-subsystem-for-linux