Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions adafruit_hid/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
class Keyboard:
"""Send HID keyboard reports."""

LED_NUM_LOCK = 0x01
"""LED Usage ID for Num Lock"""
LED_CAPS_LOCK = 0x02
"""LED Usage ID for Caps Lock"""
LED_SCROLL_LOCK = 0x04
"""LED Usage ID for Scroll Lock"""
LED_COMPOSE = 0x08
"""LED Usage ID for Compose"""

# No more than _MAX_KEYPRESSES regular keys may be pressed at once.

def __init__(self, devices):
Expand Down Expand Up @@ -143,3 +152,29 @@ def _remove_keycode_from_report(self, keycode):
for i in range(_MAX_KEYPRESSES):
if self.report_keys[i] == keycode:
self.report_keys[i] = 0

@property
def led_status(self):
"""Returns the last received report"""
return self._keyboard_device.last_received_report

def led_on(self, led_code):
"""Returns whether an LED is on based on the led code

Examples::

import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
import time

# Press and release CapsLock.
kbd.press(Keycode.CAPS_LOCK)
time.sleep(.09)
kbd.release(Keycode.CAPS_LOCK)

# Check status of the LED_CAPS_LOCK
print(kbd.led_on(Keyboard.LED_CAPS_LOCK))

"""
return bool(self.led_status[0] & led_code)