Python evdev 练习:列出可访问的设备

Python evdev 练习:列出可访问的设备

16.04 安装了 evdev 模块,目标:重现截图中的例子:

在此处输入图片描述

我的尝试的截图:

在此处输入图片描述

“IndentationError”错误表示需要采取什么纠正措施?如何才能重现 16.04 实例上的设备列表?如果您能够重现练习在您的盒子上,请在您的回复中注明这一点。

EVDEV 安装确认:

>>> import evdev
>>> device = evdev.InputDevice('/dev/input/event0')
>>> print(device)
device /dev/input/event0, name "Logitech M325", phys "usb-3f980000.usb-1.3:1"

更新:Rinzwind 已经将主题推向正确的方向(无“IndentationError”):

>>> devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
>>> import evdev
>>> devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
>>> for device in devices:
...     print(device.fn, device.name, device.phys)
...     print(device.fn, device.name, device.phys)
... 

想知道这个观察结果是否与故障排除相关:

>>> import evdev
>>> devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
>>> for device in devices: ...      print(device.fn, device.name, device.phys) ... 
>>> device = evdev.InputDevice('/dev/input/event3') Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "/usr/local/lib/python2.7/dist-packages/evdev/device.py", line 129, in
__init__
    fd = os.open(dev, os.O_RDONLY | os.O_NONBLOCK) OSError: [Errno 13] Permission denied: '/dev/input/event3'

在哪里:

cat /proc/bus/input/devices

I: Bus=0011 Vendor=0001 Product=0001 Version=ab41
N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input3

继续寻求建议和指导。

答案1

Python 有强制缩进。

在带有“for”的行之后,必须缩进(4 个空格或一个制表符)。因此,请在“print”之前添加它们。这些空格在第一张图片中;)

相关内容