PS4 Button Box code question

so i’m playing around a little bit with my Leonardo and modified a code i found here to fit my needs, not sure if it will work the way i want it to…i just want to have a 25 button box with just simple keyboard.press commands…nothing over the top. i know that this sketch is not really finished (as of right now i only have 20 buttons…that’s no big deal for me to add more buttons).
maybe a pro could have a quick close looke over the code to confirm that i want hurt my board.
thanks in advance guys!

#include <Keypad.h>
#include <Keyboard.h>

const byte ROWS = 4; // Four rows
const byte COLS = 5; // Three columns
// Define the Keymap
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','4','5'},
  {'6','7','8','9','A'},
  {'B','C','D','E','F'},
  {'G','H','I','J','K'}
 
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 0, 1, 2, 3 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 4, 5, 6, 7, 8 };

// Create the Keypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS );


unsigned long loopCount;
unsigned long startTime;
String msg;

void setup()
{
  
  Serial.begin(9600);

    loopCount = 0;
    startTime = millis();
    msg = "";
    customKeypad.addEventListener(keypadEvent);
    customKeypad.setHoldTime(500);
 
 
}

void loop()
{
  loopCount++;
    if ( (millis()-startTime)>5000 ) {
        Serial.print("Average loops per second = ");
        Serial.println(loopCount/5);
        startTime = millis();
        loopCount = 0;
    }

    // Fills kpd.key[ ] array with up-to 10 active keys.
    // Returns true if there are ANY active keys.
    if (customKeypad.getKeys())
    {
        for (int i=0; i<LIST_MAX; i++)   // Scan the whole key list.
        {
            if ( customKeypad.key[i].stateChanged )   // Only find keys that have changed state.
            {
                switch (customKeypad.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                    case PRESSED:
                    msg = " PRESSED.";
                   
                break;
                   case HOLD:
                    msg = " HOLD.";
                break;
                    case RELEASED:
                    msg = " RELEASED.";
                break;
                    case IDLE:
                    msg = " IDLE.";
                }
                Serial.print("Key ");
                Serial.print(customKeypad.key[i].kchar);
                Serial.println(msg);
            }
        }
 
 
  }

}
void keypadEvent(KeypadEvent key){
    switch (customKeypad.getState()){

   
    case PRESSED: 
       
        if (key == '9') {                                   //Headlights On/Off (cant use toggle switch)
            Keyboard.press('9');
            delay(50);
            Keyboard.release('9');
           
        }
         if (key == '6') {                                   //ABS On (cant use toggle switch)
            Keyboard.press('6');
            delay(50);
            Keyboard.release('6');
        }
          if (key == '7') {                                   //ESP On (cant use toggle switch)
            Keyboard.press('7');
            delay(50);
            Keyboard.release('7');
        }
          if (key == '8') {                                   //TCS On (cant use toggle switch)
            Keyboard.press('8');
            delay(50);
            Keyboard.release('8');
        }
         if (key == 'B') {                                   //ABS Off (cant use toggle switch)
            Keyboard.press('b');
            delay(50);
            Keyboard.release('b');
        }
          if (key == 'C') {                                   //ESP Off (cant use toggle switch)
            Keyboard.press('c');
            delay(50);
            Keyboard.release('c');
        }
          if (key == 'D') {                                   //TCS Off (cant use toggle switch)
            Keyboard.press('d');
            delay(50);
            Keyboard.release('d');
        }
       
         if (key == '1') {                                   //Switch MoTec
            Keyboard.press('1');
            delay(50);
            Keyboard.release('1');
        }
         if (key == '2') {                                   //Reset
            Keyboard.press('2');
            delay(50);
            Keyboard.release('2');
        }
         if (key == '3') {                                   //Switch HUD
            Keyboard.press('3');
            delay(50);
            Keyboard.release('3');
        }
         if (key == '4') {                                   //Switch Lap Info
            Keyboard.press('4');
            delay(50);
            Keyboard.release('4');
        }
         if (key == '5') {                                  //Wiper On/Off and Test on ledpin13
            Keyboard.press('5');
            delay(50);
            Keyboard.release('5');
        }
        break;
     }
     }

if i verify the code it comes out “ok”

Your code is unnecessarily complex (redundant).

For all the keys, you press and release the same key as in the variable called key. You don't need code to deal with each key that way.

    case PRESSED:
       Keyboard.press(key);
       delay(50);
       Keyboard.release(key);
       break;

Way less code is good.

Thx for the info!!! i already thought it might be way to complex, but as long as it works, i would be happy for now.for one key/button i would love to have a function(on,off,on,off), i guess that should be easy to be managed with this code.