Keyboard button hold down function

so my keyboard sketch is running pretty "solid" the only thing i miss is that if i press/hold a button, it'll give me just one single stroke.....which is actually pretty good for most of the buttons! only two of the 25 i would like to have a press/hold function.
so i searched a bit an found a pretty good start sketch (IMO). the only thing i'm not sure about is how to modify it to work with my already running sketch.

this is the code i want to implement:

void loop(){

  delay(50);

  keypadLoop();

}  



void keypadLoop() {

    // Keypad related

  char key = keypad.getKey('o');

  KeyState state = keypad.getState('o');

  if (state == PRESSED && key != NO_KEY) {

    previousPressedKey = key;

    hasReleasedKey = false;

    Keyboard.print('o');

  }

  else if (state == RELEASED && !hasReleasedKey) {

    // Multiple RELEASED events occur when there had not been HOLD

    Keyboard.print('o');

    hasReleasedKey = true;

  }

  else if (state == HOLD) {

    Keyboard.print('o');

    Keyboard.println(previousPressedKey);

  }

}

i know there is more stuff above void loop, that's not the problem to add to my sketch!
can someone tell me if this is the way to add the hold function for just the 'o' key ? or do i need to change more?

the last line of my already existing sketch is:

        case 'n':
        Keyboard.press('n');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'o':
        Keyboard.press('o');
        delay(100);
        Keyboard.releaseAll();
        break;

        
        default:
        Serial.println(key);
    }
  }
}

can i just put it here???

just figured it out…i guess can someone please confirm this code, especially the last section for the ‘o’ button.thx

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

char previousPressedKey;
boolean hasReleasedKey = false;


const byte ROWS = 5; // Four rows
const byte COLS = 5; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3','4','5'},
  {'6','7','8','9','0'},
  {'a','b','c','d','e'},
  {'f','g','h','i','j'},
  {'k','l','m','n','o'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 2, 3, 4, 5, 6 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 8, 9, 10, 11, 12 }; 

// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

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

void loop()
{
  char key = kpd.getKey();
  KeyState state = kpd.getState();
  
  if(key)  // Check for a valid key.
  {
    switch (key)
    {
      case '1':
        Keyboard.press('1');
        delay(100);
        Keyboard.releaseAll();
        break;
      
      case '2':
        Keyboard.press('2');
        delay(100);
        Keyboard.releaseAll();
        break;
       
      case '3':
        Keyboard.press('3');
        delay(100);
        Keyboard.releaseAll();
        break;
      
      case '4':
        Keyboard.press('4');
        delay(100);
        Keyboard.releaseAll();
        break;
       
      case '5':
        Keyboard.press('5');
        delay(100);
        Keyboard.releaseAll();
        break;
      
      case '6':
        Keyboard.press('6');
        delay(100);
        Keyboard.releaseAll();
        break;
      
      case '7':
        Keyboard.press('7');
        delay(100);
        Keyboard.releaseAll();
        break;
        
      case '8':
        Keyboard.press('8');
        delay(100);
        Keyboard.releaseAll();
        break;
      
      case '9':
        Keyboard.press('9');
        delay(100);
        Keyboard.releaseAll();
        break;
        
      case '0':
        Keyboard.press('0');
        delay(100);
        Keyboard.releaseAll();
        break;
        
      case 'a':
        Keyboard.press('a');
        delay(100);
        Keyboard.releaseAll();
        break;
        
      case 'b':
        Keyboard.press('b');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'c':
        Keyboard.press('c');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'd':
        Keyboard.press('d');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'e':
        Keyboard.press('e');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'f':
        Keyboard.press('f');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'g':
        Keyboard.press('g');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'h':
        Keyboard.press('h');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'i':
        Keyboard.press('i');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'j':
        Keyboard.press('j');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'k':
        Keyboard.press('k');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'l':
        Keyboard.press('l');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'm':
        Keyboard.press('m');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'n':
        Keyboard.press('n');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'o':
  if (state == PRESSED && 'o' != NO_KEY) {
        previousPressedKey = 'o';
        hasReleasedKey = false;
        Keyboard.print('o');
        }

  else if (state == RELEASED && !hasReleasedKey) {
       Keyboard.print('o');
       hasReleasedKey = true;
       }

  else if (state == HOLD) {
       Keyboard.print('o');
       Keyboard.println(previousPressedKey);
       }
  
  default:
  Serial.println(key);
    
  }
 }
}
  if (state == PRESSED && 'o' != NO_KEY) {

Can you think of ANY possible way that 'o' will equal NO_KEY? If not, there is no reason to test for something that can not possibly happen.

Your code
would be a lot
easier to read
if there wasn't so damned

much of it, and if it
didn't look like

it was typed by a drunken monkey.

Use Tools + Auto Format to sober that monkey up. You seem determined to ignore my advice about reducing the amount of code you have.

of course not…must have a mistake there as i was doing this sketch in my 15 min. break at work.
i’ll put some leds with the according buttons and some other functions…and IMO that’s the easiest way to add them later…i’m really not into getting in to deep with the programming thing, since it’s just a small winter project, with that said i might not even use this stuff after my box works as i want it to.

would this work better?

void keypadEvent(KeypadEvent key){
  switch (keypad.getState()){
    case PRESSED:
      switch (key){
        case '#': digitalWrite(ledPin,!digitalRead(ledPin)); break;
        case '*': 
          digitalWrite(ledPin,!digitalRead(ledPin));
        break;
      }
    break;
    case RELEASED:
      switch (key){
        case '*': 
          digitalWrite(ledPin,!digitalRead(ledPin));
          blink = false;
        break;
      }
    break;
    case HOLD:
      switch (key){
        case '*': blink = true; break;
      }
    break;