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

Conversation

jfurcean
Copy link
Contributor

This adds the ability to read the LED status of CAPS_LOCK, NUM_LOCK, SCROLL_LOCK, & COMPOSE.

LED_NUM_LOCK  # Works on Windows, RaspberryPi
LED_CAPS_LOCK # Works on Windows, RaspberryPi, Mac
LED_SCROLL_LOCK # Works on Windows
LED_COMPOSE  # Not Tested

Test Code

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

KEY_DELAY = .09

key_actions = [
    {
        "name": "Caps Lock",
        "keycode": Keycode.CAPS_LOCK,
        "led_code": Keyboard.LED_CAPS_LOCK
    },
    {
        "name": "Caps Lock",
        "keycode": Keycode.SCROLL_LOCK,
        "led_code": Keyboard.LED_SCROLL_LOCK
    },
    {
        "name": "Caps Lock",
        "keycode": Keycode.KEYPAD_NUMLOCK,
        "led_code": Keyboard.LED_NUM_LOCK
    },
]
kbd = Keyboard(usb_hid.devices)

for action in key_actions:
    for i in range(2):
        kbd.press(action['keycode'])
        time.sleep(KEY_DELAY)
        kbd.release(action['keycode'])
        print(f"{action['name']}: {kbd.led_on(action['led_code']}"))
    print()

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! It is simple and small. A little more documentation is all that is needed.

@jfurcean jfurcean requested a review from dhalbert March 22, 2021 01:18
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this valuable addition to the library!

@dhalbert dhalbert merged commit 1f4ced5 into adafruit:master Mar 22, 2021
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Mar 24, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_BNO08X to 1.1.0 from 1.0.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_BNO08x#19 from adafruit/patch-test
  > Merge pull request adafruit/Adafruit_CircuitPython_BNO08x#14 from yugyesh/patch-3

Updating https://github.com/adafruit/Adafruit_CircuitPython_CAP1188 to 1.2.7 from 1.2.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_CAP1188#20 from adafruit/linting
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_EMC2101 to 1.1.5 from 1.1.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_EMC2101#7 from rpavlik/slim-lut
  > Merge pull request adafruit/Adafruit_CircuitPython_EMC2101#6 from rpavlik/split
  > Merge pull request adafruit/Adafruit_CircuitPython_EMC2101#9 from rpavlik/fix-lut
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI to 3.5.8 from 3.5.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#130 from adafruit/anecdata-patch-2
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_TLC5947 to 1.3.4 from 1.3.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_TLC5947#24 from adafruit/REUSE
  > "Increase duplicate code check threshold "
  > Re-added pylint install to build.yml
  > Removed pylint process from github workflow
  > Hardcoded Black and REUSE versions
  > Added pre-commit-config file
  > Added pre-commit and SPDX copyright

Updating https://github.com/adafruit/Adafruit_CircuitPython_TLV493D to 1.2.4 from 1.2.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_TLV493D#11 from lubarb/setup-edit
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_Cycling_Speed_and_Cadence to 1.1.4 from 1.1.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE_Cycling_Speed_and_Cadence#6 from adafruit/pre-commit
  > "Increase duplicate code check threshold "
  > Re-added pylint install to build.yml
  > Removed pylint process from github workflow
  > Hardcoded Black and REUSE versions
  > Added pre-commit-config file
  > Added pre-commit and SPDX copyright

Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_Layout to 1.6.0 from 1.5.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_Layout#18 from kmatch98/icon_palette
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_Layout#25 from jposada202020/main
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_Layout#24 from kmatch98/touch_fix

Updating https://github.com/adafruit/Adafruit_CircuitPython_HID to 4.2.0 from 4.1.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_HID#62 from jfurcean/add-led-status
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad to 0.14.1 from 0.14.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#48 from FoamyGuy/readinto_fallback
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#49 from kmatch98/readinto_fix

Updating https://github.com/adafruit/Adafruit_CircuitPython_MIDI to 1.3.4 from 1.3.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_MIDI#34 from adafruit/test-lint
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_PIOASM to 0.3.0 from 0.2.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_PIOASM#19 from adafruit/add-tests
  > Merge pull request adafruit/Adafruit_CircuitPython_PIOASM#18 from adafruit/jepler-rxuart-example
  > "Increase duplicate code check threshold "
@jfurcean jfurcean deleted the add-led-status branch April 9, 2021 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants