0

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!

rupiman
  • 11
  • 2
  • what a strange error! the error is complaining about the read() function being called without arguments, but it points to it being called with an argument 64. Is there any documentation for this read function? should it be called with a string or some other number? – Matthias Feb 14 '23 at 09:11
  • Hello, I have screwed up the failure message. I have updated the picture with the correct one, now it stops for "read error". So the problem is not with the missing argument I think. – rupiman Feb 14 '23 at 15:12

0 Answers0