chegewara / EspTinyUSB

ESP32S2 native USB library. Implemented few common classes, like MIDI, CDC, HID or DFU (update).
MIT License
488 stars 70 forks source link

HIDcomposite key repeat issue with Raspberry Pi #88

Open jokkebk opened 2 years ago

jokkebk commented 2 years ago

I was trying to use EspTinyUSB library based device with a fresh Raspberry Pi OS install (64 bit, RaspPi4 HW) and turns out the sent keys get "stuck", i.e. device.sendKey(HID_KEY_A); results in aaaaaaaaaaaaaaaaaaaaaa... instead of a single letter.

Sample code to reproduce:

#include "hidcomposite.h"

HIDcomposite device;

void setup() { 
    device.begin();
}

void loop() {
    device.sendKey(HID_KEY_A);
    delay(1000);
}

I assumed it might related to how Linux handles key repeat and release delays vs. Windows (and it could be), but what is strange, that using HIDkeyboard instead of a composite device works just fine. Could there be some difference that causes the sendPress to fail with a composite device, or sendRelease not succeeding?

My knowledge of the raw HID reports is rusty & largely missing, but happy to investigate further, if there are any pointers what to check first (relying on single led and no serial ATM).

chegewara commented 2 years ago

Yes, it may be the problem with timing. I am suggesting to play with last parameter in this line: https://github.com/chegewara/EspTinyUSB/blob/master/src/device/hid/hidkeyboard.cpp#L16 and delay in this line (delay should be longer than the other param): https://github.com/chegewara/EspTinyUSB/blob/master/src/device/hid/hidkeyboard.cpp#L34

PS usually first line parameter should be 10, but i decided to make it 1 to let faster sending keys