Форум сайта python.su
0
Поставил себе задачу обнаружить, присутствует ли в USB клавиатура или нет. Копаясь в сети, набрёл на команду lsusb. Присобачил сюда. Прошу помочь найти более изысканные решения, прокомментировать моё и направить в нужную сторону.
def check_keyboard_usb(): import subprocess proc = subprocess.Popen(["lsusb -v"], stdout=subprocess.PIPE, shell=True) (out, err) = proc.communicate() if "Keyboard" in out: return True else: return False
Офлайн
61
import usb for dev in usb.core.find(find_all=True): print "Device:", dev.filename print " idVendor: %d (%s)" % (dev.idVendor, hex(dev.idVendor)) print " idProduct: %d (%s)" % (dev.idProduct, hex(dev.idProduct))
Офлайн
1
Офлайн
61
Что уже настока обленились что впадлу тыкнуть мышкой по линку и прочесть
PyUSB aims to be an easy to use Python module to access USB devices. PyUSB relies on a native system library for USB access. Currently, it works out of the box with libusb 0.1, libusb 1.0, libusbx, libusb-win32 and OpenUSB, and works with any Python version starting at 2.4, including Python 3 releases.
Офлайн
1
ZerGЯ очень извиняюсь, но по приведённой Вами ссылке приведённой вами же цитаты не увидел
PyUSB aims to be an easy to use Python module to access USB devices. PyUSB relies on a native system library for USB access. Currently, it works out of the box with libusb 0.1, libusb 1.0, libusbx, libusb-win32 and OpenUSB, and works with any Python version starting at 2.4, including Python 3 releases.
Отредактировано Kostilo (Ноя. 24, 2015 08:43:42)
Офлайн
61
Portability:Да уж….
PyUSB should run on any platform with Python >= 2.4, ctypes and at least one of the supported builtin backends.
Офлайн