USB HID proper key release

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

which doesn't quite does the job.

Perhaps one of the modifier bits is a press/release flag?

So I've found well call it a solution.

So the actual buffer that gets send is 8bytes long and looks like this:

  buf[0] = 0x00; //Modifier
  buf[1] = 0x00; //Padding
  buf[2] = 0x04 //Pressed key
  buf[3] = 0x16 //Next pressed key
  buf[4] = 0x07 //Next pressed key
  buf[5] = 0x09 //...
  buf[6] = 0x0A 
  buf[7] = 0x28 
  Serial.write(buf, 8);

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.

But these controllers also support TMK (GitHub - tmk/tmk_keyboard: Keyboard firmwares for Atmel AVR and Cortex-M) which everyone doing more complex projects with keyboards should also have a look at.