Bluetooth Keyboard Using arduino-pico

Hi guys, Im trying to build a mechanical keyboard using arduino - pico project with a raspberry pi pico W, I have used the keyboard code from 'datulab tech' and modified it quite a bit actually it almost works except for the modifier keys, i want the shift, ctrl , tab keys to act normally like they should stay pressed for the time they are actually presses, but with my code they keep spamming if you hold the key for more than 350 ms it starts spamming that modifier key, which is not what i want , (I have read somewhere that you need to use debounce time but i'm pretty new to programming and don't know how to implement that ). any help and suggestions will be greatly appreciated. i'm attaching my code below



/*--------------------------------------------------------------------------
 * This code was written by David Wieland aka. Datulab Tech 
 * https://www.youtube.com/datulabtech to work with the 
 * custom PCBs showcased in this video: https://youtu.be/eH8FnLNZwlk
 * A more detailed explanation can be found here: https://youtu.be/Iq3oY91x9Vk
 * Feel free to use it for your projects, just know that you will have to 
 * change some things for it to work with your hardware.
 * ------------------------------------------------------------------------- */

#include <Keyboard.h>
#include <KeyboardBLE.h>


int longPressDelay = 350;           //customizable encoderValues
int spamSpeed = 15;
int rowval=5;
int colval=7;
byte inputs[] = {16,17,18,19,20,21,22};          //declaring inputs and outputs
const int inCount = sizeof(inputs)/sizeof(inputs[0]);
byte outputs[] = {0,1,2,3,4};
const int outCount = sizeof(outputs)/sizeof(outputs[0]);

char layout[5][7] = {               //layout grid for characters
  {KEY_ESC,   '1',   '2',   '3',   '4',   '5',   '6'},
  {KEY_TAB,    'Q',    'W',    'E',    'R',    'T',    'Y'},
  {KEY_CAPS_LOCK,    'A',    'S',    'D',    'F',    'G',    'H'},
  {KEY_LEFT_SHIFT,    'Z',    'X',    'C',    'V',    'B',    'N'},
  {KEY_LEFT_CTRL, KEY_LEFT_GUI, KEY_LEFT_ALT,'[',  KEY_PAUSE,'[' , '}'},
};



int keyDown[5][7];
bool keyLong[5][7];

void setup(){
  
  for(int i=0; i<outCount; i++){    //declaring all the outputs and setting them high
    pinMode(outputs[i],OUTPUT);
    digitalWrite(outputs[i],HIGH);
  }
  for(int i=0; i<inCount; i++){     //declaring all the inputs and activating the internal pullup resistor
    pinMode(inputs[i],INPUT_PULLUP);
  }
  
 Serial.begin(115200);
  KeyboardBLE.begin();
  delay(5000);

}

//Main loop going through all the keys, then waiting 0.5ms
void loop() {
  for (int i=0; i<rowval; i++)
  {    
    digitalWrite(outputs[i],LOW);   //setting one row low
    delayMicroseconds(5);           //giving electronics time to settle down
    
    for(int j=0; j<colval; j++)
    {
      if(digitalRead(inputs[j]) == LOW)
      {
        keyPressed(i,j);            //calling keyPressed function if one of the inputs reads low
      }
      else if(keyDown[i][j] != 0)   //resetting the key if it is not pressed any more
      {  
        resetKey(i,j);
      }
    }
    
    digitalWrite(outputs[i],HIGH);
    delayMicroseconds(500);         //setting the row high and waiting 0.5ms until next cycle
  }

}

//if a key is pressed, this Funtion is called and outputs to serial the key location, it also sends the keystroke if not already done so
void keyPressed(int row, int col){
  Serial.print("Output: "); 
  Serial.print(row);
  Serial.print(" Input: ");
  Serial.print(col);
  Serial.print(" ");
  Serial.println(layout[row][col]);

  if(keyDown[row][col]==0){         //if the function is called for the first time for this key
    KeyboardBLE.press(layout[row][col]);
    KeyboardBLE.releaseAll();
  }
  else if(keyLong[row][col] && keyDown[row][col] > spamSpeed){ //if the key has been held long enough to warrant another keystroke set
    KeyboardBLE.press(layout[row][col]);
    keyDown[row][col] = 1;
  }
  else if(keyDown[row][col] > longPressDelay){ //if the key has been held for longer that longPressDelay, it switches into spam mode
    keyLong[row][col] = true;
  }

  keyDown[row][col]++;
}

void resetKey(int row, int col){ //resetting the variables after key is released
  keyDown[row][col] = 0;
  keyLong[row][col] = false;
}

You can't release the key if you want it to be held down, such as the shift key. You should release the key in your resetKey() function.

Could you pls show me how to do that, as I am quite confused.

  if(keyDown[row][col]==0){         //if the function is called for the first time for this key
    KeyboardBLE.press(layout[row][col]);
    // KeyboardBLE.releaseAll();
  }
...

void resetKey(int row, int col){ //resetting the variables after key is released
  keyDown[row][col] = 0;
  keyLong[row][col] = false;
  KeyboardBLE.release(layout[row][col]);
}

Thank you so much man
, you are an angel :innocent: