forked from adafruit/circuitpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_keyboard.py
More file actions
40 lines (34 loc) · 962 Bytes
/
basic_keyboard.py
File metadata and controls
40 lines (34 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import array
import usb.core
import sys
import time
# This is a WASD Code Keyboard with a generic controller in it.
USB_VID = 0x04D9
USB_PID = 0x0169
# This is ordered by bit position.
MODIFIERS = []
device = None
while device is None:
device = usb.core.find(idVendor=USB_VID, idProduct=USB_PID)
time.sleep(0.1)
device.set_configuration()
print(device.manufacturer, device.product, device.serial_number)
# Test to see if the kernel is using the device and detach it.
if device.is_kernel_driver_active(0):
device.detach_kernel_driver(0)
# Boot keyboards have 8 byte reports
buf = array.array("B", [0] * 8)
report_count = 0
while True:
try:
count = device.read(0x81, buf)
except usb.core.USBTimeoutError:
continue
if report_count % 15 == 0:
print("modifiers keys")
print(buf[0], end=" ")
for i in range(2, 8):
if buf[i] > 0:
print(buf[i], end=" ")
print()
report_count += 1