pyudev输出的设备多于已连接的设备

时间:2019-03-30 19:45:17

标签: python usb pyudev

下面带有pyudev的用于打印所有连接的USB鼠标的Python 3代码显示3行,尽管仅连接了1个鼠标。

输出:

Device('/sys/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0/0003:062A:4102.0001/input/input12')
Device('/sys/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0/0003:062A:4102.0001/input/input12/event6')
Device('/sys/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0/0003:062A:4102.0001/input/input12/mouse0')

为什么1个鼠标设备有3条线,如何固定?

代码:

#!/usr/bin/python3
import pyudev


class MouseMonitor:

    def __init__(self):
        self._context = pyudev.Context()

        self._monitor = pyudev.Monitor.from_netlink(self._context)
        self._monitor.start()

        devices = self._context.list_devices(subsystem="input", ID_INPUT_MOUSE=True)
        for device in devices:
            print(device)


if __name__ == "__main__":
    mouse_monitor = MouseMonitor()

0 个答案:

没有答案