mirror of
https://github.com/wahyd4/raspberry-pi.git
synced 2026-08-08 20:36:36 +10:00
31 lines
654 B
Python
31 lines
654 B
Python
import usb.core
|
|
import usb.util
|
|
import time
|
|
|
|
USB_IF = 0 # Interface
|
|
USB_TIMEOUT = 5 # Timeout in MS
|
|
|
|
USB_VENDOR = 0x045e # Rii
|
|
USB_PRODUCT = 0x028e # Mini Wireless Keyboard
|
|
|
|
dev = usb.core.find(idVendor=USB_VENDOR, idProduct=USB_PRODUCT)
|
|
|
|
endpoint = dev[0][(0,0)][0]
|
|
|
|
if dev.is_kernel_driver_active(USB_IF) is True:
|
|
dev.detach_kernel_driver(USB_IF)
|
|
|
|
usb.util.claim_interface(dev, USB_IF)
|
|
|
|
while True:
|
|
control = None
|
|
|
|
try:
|
|
control = dev.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize, USB_TIMEOUT)
|
|
print(control)
|
|
print(control[2])
|
|
except:
|
|
pass
|
|
|
|
time.sleep(0.1) # Let CTRL+C actually exit
|