Hello everyone,
I am currently trying to upgrade my Guitar Hero Controller project from a simple serial -> interpreter -> keystroke simulator to be recognized as an usb hid. This works fine i've flashed the 16u2 on my Uno r3 und i am able to send keystrokes as a native keyboard.
But now i need a proper way to release keys.
As it is crucial for my project to hold down certain keys. So I need full control over which key gets released when. The only way I found online to release keys was sending 0x0000
uint8_t buf[8] = { 0 };
(...)
buf[0] = 0x00; //Modifier
buf[2] = 0x04; //Keycode: a or A
Serial.write(buf, 8); //Press A
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
Bitwise and'ing each key placeholder with a byte that gets set (0xFF) when the key is pressed and unset when it is released should actually do the job. Somehow this bugged out badly on my end. I am assuming that the 16u2 is just not fast enough for handling glitching keys as sometimes some keys got pressed extremly fast again as I am using not really optimized capacitive touch sensing for triggering key presses. This stucked something and I often had to restart my system as the stuck keys weren't released anymore and I couldn't interact with my computer properly anymore.
I am now using a 32u4 controller (used on e.g. leonardo; micro) which natively support the Keyboard Lib; This works perfectly.