Skip to content

Add the ability to use the LED indicators for CAPS_LOCK et al. #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2021
Merged
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions adafruit_hid/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
class Keyboard:
"""Send HID keyboard reports."""

LED_NUM_LOCK = 0x01
LED_CAPS_LOCK = 0x02
LED_SCROLL_LOCK = 0x04
LED_COMPOSE = 0x08

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

def __init__(self, devices):
Expand Down Expand Up @@ -143,3 +148,12 @@ 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"""
return bool(self.led_status[0] & led_code)