Y
Y
yahabrovec2018-08-27 22:43:21
Python
yahabrovec, 2018-08-27 22:43:21

How to check which devices are connected to pc using python?

Hello everyone
. I'm making my bot here, and suddenly I wanted to add the function of checking devices connected to the PC to it (there's just nothing to do). Tell me where to dig, what libraries to use?
PS Ideally, everything should be reduced to a small simple function that will return a list or tuple with connected devices. Like this - ["mouse" , "keyboard" , "webcam"]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex F, 2018-08-29
@yahabrovec

For HID(keyboard-mouse)
Example:

import usb
busses = usb.busses()
for bus in busses:
    devices = bus.devices
    for dev in devices:
        handle = dev.open()
        print("Device:", dev.filename)
        print("  VID: 0x{:04x}".format(dev.idVendor))
        print("  PID: 0x{:04x}".format(dev.idProduct))
        print("  Manufacturer: 0x{:x}".format(dev.iManufacturer), end='')

Read more here

A
Ark Tarusov, 2018-08-28
@kreo_OL

run the command line and send "{path} adb devices" to it, in response you will receive a list of androids.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question