3

我有一个在 python3.4 上运行的 python 脚本并使用该包keyboard来允许键绑定;

keyboard.add_hotkey("enter", self.listener.stop, suppress=True)
keyboard.add_hotkey("shift+enter", self.listener.finish, suppress=True)

当我在 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", self.listener.stop, suppress=True)
  File "/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/__init__.py", line 637, in add_hotkey
    _listener.start_if_necessary()
  File "/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/_generic.py", line 35, in start_if_necessary
    self.init()
  File "/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/__init__.py", line 194, in init
    _os_keyboard.init()
  File "/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/_nixkeyboard.py", line 113, in init
    build_device()
  File "/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/_nixkeyboard.py", line 110, in build_device
    device = aggregate_devices('kbd')
  File "/usr/local/lib/python3.6/dist-packages/keyboard-0.13.2-py3.6.egg/keyboard/_nixcommon.py", line 168, in aggregate_devices
    assert fake_device
AssertionError

如果有人知道如何解决这个问题或有一个很好的解决方法。请告诉我。

4

0 回答 0