Read keyboard led status

Hi,

I was wondering if it were possible to read the status of a computers keyboard LEDs when using an Arduino (the Micro, for instance) as a keyboard?

Ideally, I would like to use a toggle of one of the capslock/numlock/scrolllock leds (instigated by a user tapping a key [e.g., capslock] twice in quick succession) as a trigger to run some Arduino code.

I searched the forum, thinking this would probably have been asked before, but I was unable to find any topic about it.

Any ideas?

What do you mean by "using an Arduino as a keyboard"? The Micro or Leonardo can send keycodes to a PC but to my knowledge the other way around (reading some commands from the PC like turning on an LED or similar) hasn't been implemented yet. Have you built a complete keyboard using an Arduino? I'm asking because my USB keyboard does not light up the caps lock LED when I press caps lock on the internal keyboard of my notebook. If that's the way you intended it to work you might have a fundamental failure in your projects architecture.

I have an external usb keyboard of which the status leds follow the leds of the internal keyboard of my laptop. So if I press numlock on my laptop, the numlock leds of both the laptop and the external usb keyboard light up.

I meant 'using the Arduino as a keyboard' using the Keyboard libraries (http://arduino.cc/en/Reference/MouseKeyboard) to send keypresses. I was considering building something akin to this usb-password-typer. http://ob-security.info/?p=631

So I guess catching the led status should be possible via usb, but it might indeed not be implemented in the keyboard library yet.

victorclaessen:
I have an external usb keyboard of which the status leds follow the leds of the internal keyboard of my laptop. So if I press numlock on my laptop, the numlock leds of both the laptop and the external usb keyboard light up.

I meant 'using the Arduino as a keyboard' using the Keyboard libraries (http://arduino.cc/en/Reference/MouseKeyboard) to send keypresses. I was considering building something akin to this usb-password-typer. http://ob-security.info/?p=631

So I guess catching the led status should be possible via usb, but it might indeed not be implemented in the keyboard library yet.

Did you find anything about this? I am searching for the same feature. May be we need to modify the Keyboard library at HID.cpp...

I'm working on a Leonardo/Micro based USB interface for my good old Cherry G80-2100 keyboard and stumbled across the lack of keyboard LED support, this is what I've come up with over the weekend:

usb_key_leds.diff (3.01 KB)

Hi Hartmut,

Somehow I completely missed your reply. I guess the notify-me settings expires after a while.

Thanks a lot for that, that is really something!

I applied the patch to the files in Arduino 1.0.1 (did not work with 1.5.2) and made this simple sketch, which outputs the keyboard led status to the serial port (and blinks to show its working). I post it here below for others that may stumble onto this post.

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT); 
  Serial.begin(9600);  
}

// the loop routine runs over and over again forever:
void loop() {
  int keyled = Keyboard.getLedStatus();
  Serial.println(keyled);
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(100);               // wait for a second
}

hey,

how can i get numlock code if im use keyboard.h library?

Refer to the other thread Leonardo keyboard leds emulation? - Programming Questions - Arduino Forum