Python evdev 找不到设备
Python evdev not finding devices
我正在使用 python 编写游戏,我需要使用 evdev 监视键盘事件。我是这个库的新手,所以我按照在线教程进行操作。以下是教程中提到的脚本:
>>> import evdev
>>> devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
>>> for device in devices:
>>> print(device.path, device.name, device.phys)
然而,在运行代码之后,list_devices()的输出是None,这表明我的电脑(戴尔笔记本电脑)上没有输入设备。为什么?
在我的 debian
Buster 系统上检查过它,我认为它对你来说应该是一样的——你需要特殊的访问权限才能读取和写入设备。例如,sudo
应该有效,尝试:
bash>sudo python3
>>>import evdev; evdev.list_devices()
找到相关的doc:
If you do not see any devices, ensure that your user is in the correct group (typically input) to have read/write access.
所以将您的用户添加到 input
组 - 可能比 sudo
.
更安全
我正在使用 python 编写游戏,我需要使用 evdev 监视键盘事件。我是这个库的新手,所以我按照在线教程进行操作。以下是教程中提到的脚本:
>>> import evdev
>>> devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
>>> for device in devices:
>>> print(device.path, device.name, device.phys)
然而,在运行代码之后,list_devices()的输出是None,这表明我的电脑(戴尔笔记本电脑)上没有输入设备。为什么?
在我的 debian
Buster 系统上检查过它,我认为它对你来说应该是一样的——你需要特殊的访问权限才能读取和写入设备。例如,sudo
应该有效,尝试:
bash>sudo python3
>>>import evdev; evdev.list_devices()
找到相关的doc:
If you do not see any devices, ensure that your user is in the correct group (typically input) to have read/write access.
所以将您的用户添加到 input
组 - 可能比 sudo
.