Skip to content

Commit 2265ac3

Browse files
committed
* update hid_keyboard example
1 parent abba54a commit 2265ac3

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

examples/peripheral/usb/hid_keyboard.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
keyboard = hid.Hid(hid.DeviceType.DEVICE_KEYBOARD)
66
except Exception as e:
77
print(e)
8-
print('The HID evice is not enabled')
8+
print('The HID device is not enabled')
99
print('Try: Use the application Settings -> USB Settings -> HID Keyboard, then click Confirm, and restart the system.')
1010
print('You can also use examples/tools/maixcam_switch_usb_mode.py to enable the HID Keyboard, then restart the system.')
1111
exit(0)
1212

13-
# Refer to the "Universal Serial Bus HID Usage Tables" section of the official documentation(https://www.usb.org).
14-
keys = [21, 22, 23, 24, 25, 0] # [r, s, t, u, v, 0], 0 means release.
15-
16-
for key in keys:
13+
def press(keyboard, key):
1714
keyboard.write([0, 0, key, 0, 0, 0, 0, 0])
15+
time.sleep_ms(50)
16+
keyboard.write([0, 0, 0, 0, 0, 0, 0, 0]) # key=0, means release
17+
18+
# Refer to the "Universal Serial Bus HID Usage Tables" section of the official documentation(https://www.usb.org).
19+
press(keyboard, 21) # press 'r'
20+
press(keyboard, 22) # press 's'
21+
press(keyboard, 23) # press 't'
22+
press(keyboard, 24) # press 'u'
23+
press(keyboard, 25) # press 'v'
1824

1925
print('OK')

0 commit comments

Comments
 (0)