help in using keypad library to my own functioning Usb Midi Keyboard

many many thanks for help in my preveious topic,,,
Now i have tested keypad libray with 2x3 matrix using 6 buttons.
actually i want to make my own functioning Usb Midi keyboard with42keys+ 7 function button..
as there is sketch i have tested & modified from inbuilt example,,,,,

#include <Keypad.h>                                    //  tested

const byte ROWS = 2; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'}

};
byte rowPins[ROWS] = {1, 0}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {5, 6, 7}; //connect to the column pinouts of the kpd

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



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

void loop() {

    if (kpd.getKeys())
    {                 for (int i=0; i<LIST_MAX ;i++)  {                                       
            if   (kpd.key[i].stateChanged  && (kpd.key[i].kstate == PRESSED)) 
            {
                Serial.print("Key ");
                Serial.print(kpd.key[i].kchar);
                Serial.println("DUBBTA");
            }
                        if   (kpd.key[i].stateChanged  && (kpd.key[i].kstate == RELEASED))
            {
                Serial.print("Key ");
                Serial.print(kpd.key[i].kchar);
                Serial.println("CHDTA ");
            }
    } 
    }
}  // End loop

here are functions ,which i want to understand and use in my sketch.

(1) if my target matrix 7x7 ,,49buttons, (Button1,Button2,Button3,.......Button49)
then what & where should be change in code???????

(2) in loop function , ( If button1 is pressesd/released ,do this ) and ( if button2 is pressed/released
do that ) what changes for assign diffrent functions from different buttons ?????

(3) if button44 is hold and button45 is pressed , do some different,,,,,......for this operation what changes should be done in code??
please help or hint ,,,,,,,,,,,,thank you

charnjit:
(1) if my target matrix 7x7 ,,49buttons, (Button1,Button2,Button3,.......Button49)then what & where should be change in code???????

const byte ROWS = 7; //four rows
const byte COLS = 7; //three columns
// For key codes you can use any number between 1 and 127
char keys[ROWS][COLS] = {
{1,2,3,4,5,6,7},
{8,9,10,11,12,13,14},
...
{43,44,45,46,47,48,49}
};
byte rowPins[ROWS] = {2, 3, 4, 5, 6, 7, 8}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {9, 10, 11, 12, A0, A1, A3}; //connect to the column pinouts of the kpd

charnjit:
(2) in loop function , ( If button1 is pressesd/released ,do this ) and ( if button2 is pressed/released
do that ) what changes for assign diffrent functions from different buttons ?????

To get the 'released' events you will have to use some advanced features of the Keypad library. See File-Examples->Keypad->MultiKey

charnjit:
(3) if button44 is hold and button45 is pressed , do some different,,,,,......for this operation what changes should be done in code??

To use multiple, simultaneous, keys you will have to use some advanced features of the Keypad library. See File-Examples->Keypad->MultiKey

thank you john wasser,,,,

please check this code ,,,what is wrong with my code

#include <Keypad.h>                                   

const byte ROWS = 7; //seven rows
const byte COLS = 7; //seve columns
char keys[ROWS][COLS] = {
{1,2,3,4,5,6,7},
{8,9,10,11,12,13,14},
{15,16,17,18,19,20,21},
{22,23,24,25,26,27,28},
{29,30,31,32,33,34,35},
{36,37,38,39,40,41,42},
{43,44,45,46,47,48,49}
};
byte rowPins[ROWS] = {1, 0, 4, 5, 6, 7, 8}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {9, 10, 16, 14, 15, 18, 19}; //connect to the column pinouts of the kpd
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

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

void loop() {
          
    if (kpd.getKeys())
    {                 for (int i=0; i<LIST_MAX ;i++)  {                                       
           if   (kpd.key[i].stateChanged  && (kpd.key[i].kstate == PRESSED) && (kpd.key[i].kchar == 1))   // *********************************************** 1
            {

                 Serial.println ("1 is pressed");
                 
            }
           if   (kpd.key[i].stateChanged  && (kpd.key[i].kstate == RELEASED) && (kpd.key[i].kchar == 1))   // *********************************************** 1
            {
 
                 Serial.println ("1 is released");
            }
        // ______________________________________________________________________________________________________________________________________________________________    
             if   (kpd.key[i].stateChanged  && (kpd.key[i].kstate == PRESSED) && (kpd.key[i].kchar == 2))   // *********************************************** 2
            {
      
                  Serial.println ("2 is pressed");
            }
             if   (kpd.key[i].stateChanged  && (kpd.key[i].kstate == RELEASED) && (kpd.key[i].kchar == 2))   // *********************************************** 2
            {
      
                Serial.println ("2 is released");
            }
        // ______________________________________________________________________________________________________________________________________________________________   
                   if   (kpd.key[i].stateChanged  && (kpd.key[i].kstate == PRESSED) && (kpd.key[i].kchar == 3))   // *********************************************** 3
            {
    
                 Serial.println ("3 is pressed");
            }
                       if   (kpd.key[i].stateChanged  && (kpd.key[i].kstate == RELEASED) && (kpd.key[i].kchar == 3))   // *********************************************** 3
            {
      
                Serial.println ("3 is released");
            }
        // ______________________________________________________________________________________________________________________________________________________________  
   
    } 
    }
}  // End loop

i have used 1N4007 diode in matrix circuit.

when button1 is pressed ,it is giving right output in serial monitor,,(1 is pressed),,

but when 2 is presssed , it is giving (2 is pressed) & (3 is pressed)

and when 3 is presssed , it is also giving (2 is pressed) & (3 is pressed)

is it related to ghost keys?????/
please check where is fault?????????????????????????//////

What model Arduino are you using?

On an Arduino UNO, when you use Serial you can't also use Pin 0 (RX) and Pin 1 (TX) for digital I/O. Pick other pins, like I did.

When you have 49 keys it makes no sense to use a separate 'if' for every key. You can display the key number just like any other variable.

#include <Keypad.h>


const byte ROWS = 7; //seven rows
const byte COLS = 7; //seve columns
char keys[ROWS][COLS] =
{
  {1, 2, 3, 4, 5, 6, 7},
  {8, 9, 10, 11, 12, 13, 14},
  {15, 16, 17, 18, 19, 20, 21},
  {22, 23, 24, 25, 26, 27, 28},
  {29, 30, 31, 32, 33, 34, 35},
  {36, 37, 38, 39, 40, 41, 42},
  {43, 44, 45, 46, 47, 48, 49}
};
byte rowPins[ROWS] = {2, 3, 4, 5, 6, 7, 8}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {9, 10, A2, A0, A1, A4, A5}; //connect to the column pinouts of the kpd
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


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


void loop()
{


  if (kpd.getKeys())
  {
    for (int i = 0; i < LIST_MAX ; i++)
    {
      switch (kpd.key[i].kstate)
      {
        case PRESSED:
          Serial.print((unsigned int) kpd.key[i].kchar);
          Serial.println (" is PRESSED");
          break;
          
        case RELEASED:
          Serial.print((unsigned int) kpd.key[i].kchar);
          Serial.println (" is RELEASED");
          break;
          
        case IDLE:
        case HOLD:
          break;
      }
    }
  }
}  // End loop()

thank you sir ,,,
sorry for late post,,

i have tried this code to display my pressed button number

 #include <Keypad.h>

const byte ROWS = 6; //four rows
const byte COLS = 8; //three columns             // tested ok display Key number
char keys[ROWS][COLS] = {
{1,2,3,4,5,6,7,8},
{9,10,11,12,13,14,15,16},
{17,18,19,20,21,22,23,24},
{25,26,27,28,29,30,31,32},
{33,34,35,36,37,38,39,40},                 //  8 x 6
{41,42,43,44,45,46,47,48},

};
byte rowPins[ROWS] = {1, 0, 4, 5, 6, 7 }; //connect to the row pinouts of the kpd
byte colPins[COLS] = { 8, 9,  14, 15, 18, 19, 20, 21}; //connect to the column pinouts of the kpd

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


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


void loop() {

    if (kpd.getKeys())
    {
      
        for (int i=0; i<LIST_MAX; i++)   // Scan the whole key list.
        {
            if ((kpd.key[i].stateChanged ) && (kpd.key[i].kstate == PRESSED))  // Only find keys that have changed state.
            {
              int myKey = (kpd.key[i].kchar);
                {                  
                Serial.print("Key ");
                Serial.print(myKey);       //  kpd.key[i].kchar
                
                }

            }
        }
    }
}

so as my post title ,i want to do my own functioning in my this project.
please attention,,,
my matrix is 6x8 . i am using 1&0 pins in matrix,No problem all pins are working fine.
i can not use a single block of functions for key1 to key48. i am going to tell why?

actually i have 5 blocks of funtions to perform from differernts groups of keys.
all blocks are differents.
blocks are for example

   {   Block1(chan1, P1 + myKey, Vel1)}

 {   Block2(chan2, P2 + myKey, Vel2)}

 {   Block3(  y+newKey;)}

 {   Block4(chan++;)}

{   Block5(Vel++;)}

i want to use keys1 tokey17 for Block1, myKey is key number ,that should be used in Block1

---(key18 to key32) should be used for Block2. myKey should be alos used Block2

Block3 should be perform by combination of two keys,.this is different thing, i want to done it by hold key33 and pressing any key between 1 to 32. here is a variable newKey in this block. for this block(newKey should be=pressed second key number (1-32) after hold key33 ,,not use hold key number for "newKey")

Block4 should be perform ,when only key33 is pressed..

Block5 should be perform ,when only key34 is pressed..

other keys , i will use other different blocks..

i hope you uderstand my request please tell me,, what code to write in void loop ();
Or give any hints

thanks to read,,,,,,,,,,,,,,,,,,,,