Help with the N-key Rollover in the library USBHIDKeyboard for ESP32S3

The library comes with the struct that let you send 6 keys at once. But i want to send more. I have edited the Arduino standard leyboard library to allow this for others microcontrollers like ameta32u4.

USBHIDKeyboard.h

typedef struct {
  uint8_t modifiers;
  uint8_t reserved;
  uint8_t keys[6];
} KeyReport;

But in ESP32-S3 the library is different and i make the changes but the moment i change the hid.h struct that uses when doing the send report it stop working and nothing is send.

hid.h

typedef struct TU_ATTR_PACKED
{
  uint8_t modifier;   /**< Keyboard modifier (KEYBOARD_MODIFIER_* masks). */
  uint8_t reserved;   /**< Reserved for OEM use, always set to 0. */
  uint8_t keycode[6]; /**< Key codes of the currently pressed keys. */
} hid_keyboard_report_t;

USBHIDKeyboard.cpp

void USBHIDKeyboard::sendReport(KeyReport* keys)
{
    hid_keyboard_report_t report;
    report.reserved = 0;
    report.modifier = keys->modifiers;
    if (keys->keys) {
        memcpy(report.keycode, keys->keys, 6);
    } else {
        memset(report.keycode, 0, 6);
    }
    hid.SendReport(HID_REPORT_ID_KEYBOARD, &report, sizeof(report));
}

Everywhere that appears a 6 I want to change it to 61 without making it fail. What am i missing.

Have you found a way yet?
I'm also trying to add N-key rollover.

Nope. Tell me if you found :smiley:

I can increase it to 7, but it will not work at 8.
In additional to your changes, I also changed the following:

In USBHIDKeyboard.cpp

size_t USBHIDKeyboard::pressRaw(uint8_t k) 
{
    uint8_t nKey = 7;
    uint8_t i;
    if (k >= 0xE0 && k < 0xE8) {
        // it's a modifier key
        _keyReport.modifiers |= (1<<(k-0x80));
    } else if (k && k < 0xA5) {
        // Add k to the key report only if it's not already present
        // and if there is an empty slot.
        if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && 
            _keyReport.keys[2] != k && _keyReport.keys[3] != k &&
            _keyReport.keys[4] != k && _keyReport.keys[5] != k &&
            _keyReport.keys[6] != k
          ) {
            
            for (i=0; i<nKey; i++) {
                if (_keyReport.keys[i] == 0x00) {
                    _keyReport.keys[i] = k;
                    break;
                }
            }
            if (i == nKey) {
                return 0;
            }   
        }
    } else {
        //not a modifier and not a key
        return 0;
    }
    sendReport(&_keyReport);
    return 1;
}

and in

size_t USBHIDKeyboard::releaseRaw(uint8_t k)

also change 6 to 7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.