nRF Desktop: How to handle num lock on a custom keyboard

Hi,

I'm still debugging a few things on a custom keyboard project which uses nRF Desktop with nRF Connect v 2.1.0.

It seems like caps lock is handled automatically and it works, but the customer noticed that num lock wasn't resulting in numbers being sent instead of the default behavior for our keys. Which keys are supposed send which number when in num lock mode are nonstandard and custom to our keyboard - for instance when num lock is on we want the "K" key to send the number 2.

Does nRF Desktop have a way to specify which alternate keys are sent when num lock is active - or do I have to somehow detect from the HID output report that it is active and intercept and fake out the keypresses (which I've already done for some customized function key behavior)?

Thanks,

Glen

Parents
  • Hi Glen,

    Apparently, the USB HID spec specifies both the numeric and alternative meaning for those keycodes affected by num lock: https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf (page 55)

    So this mapping is universal, and from what I can tell this means that it is done completely on the host OS side. The keycode being sent from the keyboard is the same in both cases, but I'm not certain if the num lock keycode is sent once and then kept track of by the host OS, or if it's part of every report.

    Does nRF Desktop have a way to specify which alternate keys are sent when num lock is active - or do I have to somehow detect from the HID output report that it is active and intercept and fake out the keypresses (which I've already done for some customized function key behavior)?

    With your special layout, you would indeed have to keep track of num lock and replace keypresses on the firmware side, but instead of reading the output report, I recommend that you just keep track of the num lock state of the keyboard and then replace the keypresses even before the report is put together. You could probably do this any way you like, but if you already have a num lock LED on your keyboard, you could probably just hook onto that.

    Best regards,

    Raoul

  • Ok thanks - I got it working. If anyone else is ever trying to do this, there is a function in hid_state.c called 

    broadcast_keyboard_leds where you end up when you get the HID report. That calls
    update_led, which is where the led_event is generated that ultimately updates the LEDs on the keyboard. Anyway I was able to hack some code into broadcast_keyboard_leds  that saves off the num lock state.
  • Great to hear, and I appreciate you sharing your findings with other DevZone users!

    Best regards,

    Raoul

Reply Children
No Data
Related