Caps Lock Status
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Christopher37
- Posts: 4
- Joined: Sat Dec 02, 2017 11:13 pm
Caps Lock Status
Is there a way to tell the status of the caps lock with CircuitPython on a Trinket M0?
- danhalbert
- Posts: 4654
- Joined: Tue Aug 08, 2017 12:37 pm
Re: Caps Lock Status
Are you using the adafruit_hid.keyboard library? You can't tell the status of the Caps Lock LED, but you can force the Caps Lock key to be down or up, e.g.:
Note that this is on the emulated keyboard that Keyboard provides. You can't change the Caps Lock key status on your own physical keyboard from CircuitPython.
Code: Select all
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
k = Keyboard()
k.release(Keycode.CAPS_LOCK)
- Christopher37
- Posts: 4
- Joined: Sat Dec 02, 2017 11:13 pm
Re: Caps Lock Status
I was hoping to be able to use CircuitPython to read the status of the caps lock and then light some more obvious LEDs. At work I sometimes do simple Uniquery searches from the command line and ~90% of it is in uppercase; I then forget to turn off the caps lock before typing somewhere else.
I was playing around with one of the capacitive touch pins on the Trinket M0 to toggle the caps lock and it was showing the change on my physical keyboard. I even plugged in another keyboard and the change in the caps lock status made by the Trinket M0 showed on both of them. I figure if a physical keyboard can tell that something else changed it, the Trinket M0 could too.
I'm using it on Windows 7 and this is the code that toggled the caps locks and flashed the dotstar when touched. I wanted to make the dotstar different colors based on the caps lock status.
I was playing around with one of the capacitive touch pins on the Trinket M0 to toggle the caps lock and it was showing the change on my physical keyboard. I even plugged in another keyboard and the change in the caps lock status made by the Trinket M0 showed on both of them. I figure if a physical keyboard can tell that something else changed it, the Trinket M0 could too.
I'm using it on Windows 7 and this is the code that toggled the caps locks and flashed the dotstar when touched. I wanted to make the dotstar different colors based on the caps lock status.
Code: Select all
import board
import touchio
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
import adafruit_dotstar as dotstar
import time
dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.25)
# Capacitive touch on D3
touch = touchio.TouchIn(board.D3)
kbd = Keyboard()
######################### MAIN LOOP ##############################
dot[0] = [0,0,0]
while True:
if touch.value:
print("D3 touched!")
kbd.press(Keycode.CAPS_LOCK)
kbd.release_all()
dot[0] = [0, 255, 255]
while touch.value:
time.sleep(0.05);
dot[0] = [0,0,0]
- danhalbert
- Posts: 4654
- Joined: Tue Aug 08, 2017 12:37 pm
Re: Caps Lock Status
That's great! I'm glad I was wrong about the caps-lock status. I thought the driver wouldn't handle it that way.
Long term, we might be able to simulate keyboard LEDs in the Keyboard class and read their status, but right now that's not possible: we haven't implemented the reading back of LED turn-on/turn-off commands sent back from the host computer. However, it's something I should work on.
Long term, we might be able to simulate keyboard LEDs in the Keyboard class and read their status, but right now that's not possible: we haven't implemented the reading back of LED turn-on/turn-off commands sent back from the host computer. However, it's something I should work on.
Please be positive and constructive with your questions and comments.