Python hidapi, why can't read my keyboard via usb?

421 Views Asked by At

I am trying to read the data input from my keyboard in python hidapi, and print it to the console. (This is the keyboard I am currently using, but I would like to read the USB with a python code too) I can't get it to work. At data = device.read(64) line I always getting a read error. I was trying different alternatives with the help of chatGPT, start visual studio code as administrator, plug out-in the keyboard, but nothing helps.

Here is my code:

import hid

# Enumerate all connected HID devices
devices = hid.enumerate(0, 0)
for device in devices:
    print("Device:", device)

# Open a specific HID device
device = hid.device()
device.open(3690, 704)

# Read data from the device
data = device.read(64)

# Print the data
print("Data:", data)

# Close the device
device.close()

Here are the datas of my keyboard:

Device: {'path': b'\\?\HID#VID_0E6A&PID_02C0&MI_01&Col05#7&28db5c83&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD', 'vendor_id': 3690, 'product_id': 704, 'serial_number': '', 'release_number': 22529, 'manufacturer_string': 'dakai', 'product_string': 'PS/2+USB Keyboard', 'usage_page': 1, 'usage': 6, 'interface_number': 1}

Here is the failure message:

enter image description here

Thanks for your help!

0

There are 0 best solutions below