File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 2222class Keyboard :
2323 """Send HID keyboard reports."""
2424
25+ LED_NUM_LOCK = 0x01
26+ """LED Usage ID for Num Lock"""
27+ LED_CAPS_LOCK = 0x02
28+ """LED Usage ID for Caps Lock"""
29+ LED_SCROLL_LOCK = 0x04
30+ """LED Usage ID for Scroll Lock"""
31+ LED_COMPOSE = 0x08
32+ """LED Usage ID for Compose"""
33+
2534 # No more than _MAX_KEYPRESSES regular keys may be pressed at once.
2635
2736 def __init__ (self , devices ):
@@ -143,3 +152,29 @@ def _remove_keycode_from_report(self, keycode):
143152 for i in range (_MAX_KEYPRESSES ):
144153 if self .report_keys [i ] == keycode :
145154 self .report_keys [i ] = 0
155+
156+ @property
157+ def led_status (self ):
158+ """Returns the last received report"""
159+ return self ._keyboard_device .last_received_report
160+
161+ def led_on (self , led_code ):
162+ """Returns whether an LED is on based on the led code
163+
164+ Examples::
165+
166+ import usb_hid
167+ from adafruit_hid.keyboard import Keyboard
168+ from adafruit_hid.keycode import Keycode
169+ import time
170+
171+ # Press and release CapsLock.
172+ kbd.press(Keycode.CAPS_LOCK)
173+ time.sleep(.09)
174+ kbd.release(Keycode.CAPS_LOCK)
175+
176+ # Check status of the LED_CAPS_LOCK
177+ print(kbd.led_on(Keyboard.LED_CAPS_LOCK))
178+
179+ """
180+ return bool (self .led_status [0 ] & led_code )
You can’t perform that action at this time.
0 commit comments