keyboard_leds not always populated

fuzzeh

New member
I'm having an issue with reading keyboar_leds and I'm unsure is it's the OS (OSX) that's just not sending the information.

Running on a Teensy 4.0.

I have 3 keys CAPS_LOCK, NUM_LOCK and SCROLL_LOCK all of which I'd expect to be in keyboard_leds if they are active. However I'm only getting CAPS_LOCK being returned as active

Code:
KEY_CAPS_LOCK

07:48:20.603 -> Setting up
07:48:29.573 -> ROW:0 COL:10 PRESSED. SWITCH: 1
07:48:29.573 -> LAYER: 0 INDEX: 10 Press: 1
07:48:29.679 -> LAYER: 0 INDEX: 10 Press: 0
07:48:29.679 ->[B] [COLOR="#FF0000"]LEDS: 00000010[/COLOR][/B] <-- CAPS_LOCK on
07:48:35.568 -> ROW:0 COL:10 PRESSED. SWITCH: 1
07:48:35.568 -> LAYER: 0 INDEX: 10 Press: 1
07:48:35.673 -> LAYER: 0 INDEX: 10 Press: 0
07:48:35.673 -> [B]LEDS: 00000000[/B]  <-- CAPS_LOCK off

Code:
KEY_SCROLL_LOCK

07:49:05.887 -> ROW:0 COL:9 PRESSED. SWITCH: 1
07:49:05.887 -> LAYER: 0 INDEX: 9 Press: 1
07:49:05.959 -> LAYER: 0 INDEX: 9 Press: 0
07:49:05.959 -> [B][COLOR="#FF0000"]LEDS: 00000000[/COLOR][/B]  <-- SCROLL_LOCK on
07:49:16.952 -> ROW:0 COL:9 PRESSED. SWITCH: 1
07:49:16.952 -> LAYER: 0 INDEX: 9 Press: 1
07:49:17.061 -> LAYER: 0 INDEX: 9 Press: 0
07:49:17.061 -> [B]LEDS: 00000000[/B]  <-- SCROLL_LOCK off

Code:
KEY_NUM_LOCK

07:53:19.817 -> ROW:0 COL:11 PRESSED. SWITCH: 1
07:53:19.817 -> LAYER: 0 INDEX: 11 Press: 1
07:53:19.993 -> LAYER: 0 INDEX: 11 Press: 0
07:53:19.993 -> [B][COLOR="#FF0000"]LEDS: 00000000[/COLOR][/B]   <-- NUM_LOCK on
07:53:20.983 -> ROW:0 COL:11 PRESSED. SWITCH: 1
07:53:20.983 -> LAYER: 0 INDEX: 11 Press: 1
07:53:21.127 -> LAYER: 0 INDEX: 11 Press: 0
07:53:21.127 -> [B]LEDS: 00000000[/B]   <-- NUM_LOCK on


The code just outputs what's received in keyboar_leds

Code:
void printBin(byte aByte) {

  for (int8_t aBit = 7; aBit >= 0; aBit--)
         Serial.write(bitRead(aByte, aBit) ? '1' : '0');
}

   printBin(keyboard_leds);

It is a mac thing that it keyboard_leds doesn't get populated or am I missing something ?

Thanks
 
My guess is it is the MAC side, as I believe the code simply stores the led status information that the host sends to it.

But it also may be a limitation or a property of the host code, that it maybe the states are properties of each keyboard. So unless your code sent something that set that modifier state, then it won't return that led state being set or turned off.

Hard to know exactly that is going on as we don't see your code, other than your printing binary.
 
Thanks for the reply.

The code is really just a key press and a key release of KEY_CAPS_LOCK / KEY_NUM_LOCK / KEY_SCROLL_LOCK

From the research I've done since posting, I'm beginning to suspect OSX too. From what I understand the host is the one that decides and maintains what the led statuses are the client (kb) is meant to do what the host says.

I'll set up a linux machine and see if that makes a difference.

I did find a post about the code not being there to do this for Teensy 4 but that was from 2020 and I've double checked and I have the required code in the verision I'm using, so a bit of a red herring. ( you're there too ;) )

I'll report back with my findings.
 
Plugged the device into a linux machine and everything worked as expected. Another quirk of OSX I guess.
 
Back
Top