thewh1teagle / zero-hid

Raspberry pi virtual HID mouse and keyboard
GNU Lesser General Public License v3.0
71 stars 15 forks source link

Reading status of CapsLock, NumLock, ScrollLock Leds #19

Open jzhvymetal opened 3 months ago

jzhvymetal commented 3 months ago

If you plug 2x keyboards in a system you will see both will sync the lock leds. Most operating systems sync the LED on all keyboards. In the Arduino HID library, there is a UsbEventCallback that will send any connected keyboards a change in LED state.. Is there any way to read the current system status of the LEDs? Code in the Arduino HID library does not sync the LEDs, but it can easily be done once the LED statuses are captured.

Here is an example of Arduino HID code for the event handler when the LEDs change state. Is there any possibility to implement the same in this Python library?

static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){
    if(event_base == ARDUINO_USB_HID_KEYBOARD_EVENTS){
        arduino_usb_hid_keyboard_event_data_t * data = (arduino_usb_hid_keyboard_event_data_t*)event_data;
            Serial.printf("HID KEYBOARD LED: NumLock:%u, CapsLock:%u, ScrollLock:%u\n", data->numlock, data->capslock, data->scrolllock);
        }
    }
}
thewh1teagle commented 2 months ago

Hi, zero_hid uses usb gadget linux driver under the hood. I don't think that this driver supports registering / listening to caps lock change, but instead looks like there's a way to check it with polling (by sending request and getting response whether it's on / off)

jzhvymetal commented 2 months ago

Hi, zero_hid uses usb gadget linux driver under the hood. I don't think that this driver supports registering / listening to caps lock change

It might be possible that you have to change the keyboard descriptor to also include a read report. You can see an example of the descriptor that I use with CP in the link below. In the read report, it will have the states for locks and LEDs.

https://github.com/jzhvymetal/PY_Barrier/blob/main/KM_CPHID_ACTORS.py

When I find time I want to try to get my above project to also work native on the PI's that support HID in Raspbian.