multi key press function using hex keypad and keypad.h library

please see my code with hex keypad

defined while loop functions with four digit code.

while loop functions defined with

while(key==(‘1’,‘0’,‘A’,‘B’))

while(key==(‘1’,‘0’,‘A’,‘C’))

while(key==(‘1’,‘0’,‘A’,‘D’))

the above 3 function are working as soon as all the 4 keys pressed.

But when I defined another while function with “while(key==(‘1’,‘0’,‘B’,‘A’))”

Now the problem started,
the while function starting as soon as pressing three keys for example 10A and it is not waiting for fourth key input.

My program requirement is to give 4 digit input code to call the while function loop and break that loop as soon as new 4 digit code entered from hex keyapd and enter into new while loop.

please help Iam new to Arduino & ‘C’.

#include <Keypad.h>


const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8,9}; //connect to the column pinouts of the keypad

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




void setup(){


  }

  void loop()

  { char key = keypad.getKey();
      
    while(key ==('1','0','A','B'))
    {while function }

    

    while(key ==('1','0','A','C'))
    {while function }


     while(key ==('1','0','A','D'))
    {while function }


     while(key ==('1','0','B','A'))
    {while function }


  }

Please post a complete sketch

Code is for running stepper motor with different revolutions with different speeds by selecting 4 digit input code from hex keypad.

the complete code is forwarded pl.

#include <Keypad.h>
#include "LiquidCrystal.h"

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8,9}; //connect to the column pinouts of the keypad

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


const int stepPin = 10;

const int dirPin = 11;

const int enPin = 12;

LiquidCrystal lcd(22,23,24,25,26,27);

void setup(){

  pinMode(stepPin,OUTPUT);

  pinMode(dirPin,OUTPUT);

  pinMode(enPin,OUTPUT);

  digitalWrite(enPin,HIGH);

  }

  void loop()

  { char key = keypad.getKey();
      
    while(key ==('1','0','A','B'))

    {
     {digitalWrite(dirPin,HIGH);
             
         { for(int x = 0; x < 600; x++) 
         
           { digitalWrite(stepPin,HIGH);
             delayMicroseconds(2000);
             digitalWrite(stepPin,LOW);
             delayMicroseconds(2000);
           }
         }
        delay(1000);

        digitalWrite(dirPin,LOW);

         { for(int x = 0; x < 600; x++) 
         
           { digitalWrite(stepPin,HIGH);
             delayMicroseconds(2000);
             digitalWrite(stepPin,LOW);
             delayMicroseconds(2000);
           }
         }

        delay(1000);
        }

        lcd.begin(16,2);

        lcd.setCursor(0,0);
        lcd.print("I/E=1:1TV=  BR= ");

        lcd.setCursor(0,1);
        lcd.print("ORDNANACEFACTORY");

     }

     while(key ==('1','0','A','C'))

    {
     {digitalWrite(dirPin,HIGH);
             
         { for(int x = 0; x < 800; x++) 
         
           { digitalWrite(stepPin,HIGH);
             delayMicroseconds(2000);
             digitalWrite(stepPin,LOW);
             delayMicroseconds(1000);
           }
         }
        delay(1000);

        digitalWrite(dirPin,LOW);

         { for(int x = 0; x < 600; x++) 
         
           { digitalWrite(stepPin,HIGH);
             delayMicroseconds(2000);
             digitalWrite(stepPin,LOW);
             delayMicroseconds(1000);
           }
         }

        delay(1000);
        }

        lcd.begin(16,2);

        lcd.setCursor(0,0);
        lcd.print("I/E=1:1TV=  BR= ");

        lcd.setCursor(0,1);
        lcd.print("ORDNANACEFACTORY");

     }

     while(key ==('1','0','A','D'))

    {
     {digitalWrite(dirPin,HIGH);
             
         { for(int x = 0; x < 1000; x++) 
         
           { digitalWrite(stepPin,HIGH);
             delayMicroseconds(1000);
             digitalWrite(stepPin,LOW);
             delayMicroseconds(500);
           }
         }
        delay(1000);

        digitalWrite(dirPin,LOW);

         { for(int x = 0; x < 1000; x++) 
         
           { digitalWrite(stepPin,HIGH);
             delayMicroseconds(1000);
             digitalWrite(stepPin,LOW);
             delayMicroseconds(500);
           }
         }

        delay(1000);
        }

        lcd.begin(16,2);

        lcd.setCursor(0,0);
        lcd.print("I/E=  TV=  BR= ");

        lcd.setCursor(0,1);
        lcd.print("ORDNANACEFACTORY");

     }

     
  
      
   while(key ==('1','0','B','A'))
    
   {
     {digitalWrite(dirPin,HIGH);
             
         { for(int x = 0; x < 600; x++) 
         
           { digitalWrite(stepPin,HIGH);
             delayMicroseconds(500);
             digitalWrite(stepPin,LOW);
             delayMicroseconds(500);
           }
         }
        delay(1000);

        digitalWrite(dirPin,LOW);

         { for(int x = 0; x < 600; x++) 
         
           { digitalWrite(stepPin,HIGH);
             delayMicroseconds(1000);
             digitalWrite(stepPin,LOW);
             delayMicroseconds(1000);
           }
         }

        delay(1000);
        }

        lcd.begin(16,2);

        lcd.setCursor(0,0);
        lcd.print("I/E=  TV=  BR= ");

        lcd.setCursor(0,1);
        lcd.print("ORDNANACEFACTORY");

     }
   }
  while (key == ('1', '0', 'A', 'B'))

Did you invent this syntax or have you seen it used somewhere ?

UKHeliBob:

  while (key == ('1', '0', 'A', 'B'))

Did you invent this syntax or have you seen it used somewhere ?

actually i tried this syntax and this is working for 10AB, 10AC, 10AD key input.
the problem starts when i defined 10BA

odces:
actually i tried this syntax and this is working for 10AB, 10AC, 10AD key input.
the problem starts when i defined 10BA

I suggest you test it again.

edit:

while (key == '1' || key == '0' || key == 'A' || key == 'B')

pcbbc:
I suggest you test it again.

edit:

while (key == '1' || key == '0' || key == 'A' || key == 'B')

tried with above, but when i press key '1' the function starts. not waiting till completion of 4 digit input.
i need the function starts after completion of 4 digit input.

while(key==('1','0','A','B'))

while(key==('1','0','A','C'))

while(key==('1','0','A','D'))

the above 3 function are working as soon as all the 4 keys pressed.

But it does not work after all

If you want to check that 4 keys have been pressed in the correct order then the simplest way is to read each key and put it into an array. When you have read 4 keys then you can test whether they are correct

while(key==('1','0','A','B'))
while(key==('1','0','A','C'))
while(key==('1','0','A','D'))
the above 3 function are working as soon as all the 4 keys pressed.
But when I defined another while function with "while(key==('1','0','B','A'))"

The first three are equivalent to:

while(key=='B')
while(key=='C')
while(key=='D')

That is why they APPEARED to work. APPEARED to wait until you had pressed all of the keys. What they were doing was ignoring all of the keys except B, C, and D. You can test that by pressing zero or more of the ignored keys. It doesn't matter how many you press: action will begin when you press B, C, or D.

Your new case is equivalent to:

while(key=='A')

If the first three buttons in the new sequence did not include a B, C, or D then this 'sequence' would have 'worked', too. because the 3rd button is a 'B' it triggers the while(key=='B') case and never gets to the 'A' case.

UKHeliBob:
But it does not work after all

If you want to check that 4 keys have been pressed in the correct order then the simplest way is to read each key and put it into an array. When you have read 4 keys then you can test whether they are correct

I need to use four digit input code. I tried the code as below. But the error message received.

can you pl. guide me how to define a multi keypress input (4 digit input command to run the function)

Key key[16]=keypad.getKeys();

key[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','*','#'};

while(key[2],key[1],key[11],key[12])

error: could not convert '((void)0, key[12])' from 'Key' to 'bool'

johnwasser:

while(key==('1','0','A','B'))

while(key==('1','0','A','C'))
while(key==('1','0','A','D'))
the above 3 function are working as soon as all the 4 keys pressed.
But when I defined another while function with "while(key==('1','0','B','A'))"




The first three are equivalent to:


while(key=='B')
while(key=='C')
while(key=='D')



That is why they APPEARED to work. APPEARED to wait until you had pressed all of the keys. What they were doing was ignoring all of the keys except B, C, and D. You can test that by pressing zero or more of the ignored keys. It doesn't matter how many you press: action will begin when you press B, C, or D.

Your new case is equivalent to:


while(key=='A')



If the first three buttons in the new sequence did not include a B, C, or D then this 'sequence' would have 'worked', too. because the 3rd button is a 'B' it triggers the while(key=='B') case and never gets to the 'A' case.

yes sir, it is taking only single digit only. Iam in misperception that the system working for 4 digit code.

Now pl. guide me how to define 4 digit key input to call the while functions.
I have not understood how to define multikey press function with keypad.h library.

Here is an example of how it can be done

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte colPins[COLS] = {10, 11, 12, A4};
byte rowPins[ROWS] = {2, 4, 7, 8};

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

char inputBuffer[5];  //needs room for terminating '\0'
byte inputCount = 0;

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

void loop()
{
  char key = keypad.waitForKey();
  Serial.print(key);
  inputBuffer[inputCount] = key;
  inputCount++;
  inputBuffer[inputCount] = '\0'; //add termination
  if (inputCount == 4)
  {
    Serial.println();
    if (testInput() == true)
    {
      Serial.println("matched");
    }
    else
    {
      Serial.println("not matched");
    }
    inputCount = 0;  //reset the array index
  }
}

boolean testInput()
{
  if (strcmp(inputBuffer, "ABCD") == 0)
  {
    return true;
  }
  else
  {
    return false;
  }
}

NOTE
This is not the best way to do it, but it should show you the principle

1 Like

UKHeliBob:
Here is an example of how it can be done

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] =
{
 {‘1’, ‘2’, ‘3’, ‘A’},
 {‘4’, ‘5’, ‘6’, ‘B’},
 {‘7’, ‘8’, ‘9’, ‘C’},
 {’*’, ‘0’, ‘#’, ‘D’}
};

byte colPins[COLS] = {10, 11, 12, A4};
byte rowPins[ROWS] = {2, 4, 7, 8};

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

char inputBuffer[5];  //needs room for terminating ‘\0’
byte inputCount = 0;

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

void loop()
{
 char key = keypad.waitForKey();
 Serial.print(key);
 inputBuffer[inputCount] = key;
 inputCount++;
 inputBuffer[inputCount] = ‘\0’; //add termination
 if (inputCount == 4)
 {
   Serial.println();
   if (testInput() == true)
   {
     Serial.println(“matched”);
   }
   else
   {
     Serial.println(“not matched”);
   }
   inputCount = 0;  //reset the array index
 }
}

boolean testInput()
{
 if (strcmp(inputBuffer, “ABCD”) == 0)
 {
   return true;
 }
 else
 {
   return false;
 }
}




/quote]


Thank You so much. It is taking 4 digit input hex key code.

My Program requirement is the motor should run indefinitely with different speeds and revolutions as per the parameters set in function. The function should call by 4 digit hex key code. 


To run the function indefinitely while function defined.

when the new function called by input 4 digit command the running function should exit and new function should start.

how to define exit and start new function.


The code is as follows




#include “Keypad.h”
#include “LiquidCrystal.h”

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
 {‘1’,‘2’,‘3’,‘A’},
 {‘4’,‘5’,‘6’,‘B’},
 {‘7’,‘8’,‘9’,‘C’},
 {’*’,‘0’,’#’,‘D’}
};

byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8,9}; //connect to the column pinouts of the keypad

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

char inputBuffer[5];
byte inputCount =0;

const int stepPin = 10;

const int dirPin = 11;

const int enPin = 12;

LiquidCrystal lcd(22,23,24,25,26,27);

void setup(){

pinMode(stepPin,OUTPUT);

pinMode(dirPin,OUTPUT);

pinMode(enPin,OUTPUT);

digitalWrite(enPin,HIGH);

}

void loop()

{char key =keypad.waitForKey();
     inputBuffer[inputCount]=key;
     inputCount++;

inputBuffer[inputCount]=’\0’;  
     if (inputCount==4)
     {
     
     while(strcmp(inputBuffer,“10AB”)==0)
   
   {
       lcd.begin(16,2);

lcd.setCursor(0,0);
       lcd.print("I/E=1:1TV=  BR= ");

lcd.setCursor(0,1);
       lcd.print(“ORDNANACEFACTORY”);
       
        digitalWrite(dirPin,HIGH);
           
        { for(int x = 0; x < 600; x++)
       
          { digitalWrite(stepPin,HIGH);
            delayMicroseconds(2000);
            digitalWrite(stepPin,LOW);
            delayMicroseconds(2000);
          }
        }
       delay(1000);

digitalWrite(dirPin,LOW);

{ for(int x = 0; x < 600; x++)
       
          { digitalWrite(stepPin,HIGH);
            delayMicroseconds(2000);
            digitalWrite(stepPin,LOW);
            delayMicroseconds(2000);
          }
        }

delay(1000);
   
   }
 
     
 while(strcmp(inputBuffer,“10BA”)==0)    
   
  {
    {digitalWrite(dirPin,HIGH);
           
        { for(int x = 0; x < 800; x++)
       
          { digitalWrite(stepPin,HIGH);
            delayMicroseconds(1000);
            digitalWrite(stepPin,LOW);
            delayMicroseconds(1000);
          }
        }
       delay(1000);

digitalWrite(dirPin,LOW);

{ for(int x = 0; x < 800; x++)
       
          { digitalWrite(stepPin,HIGH);
            delayMicroseconds(500);
            digitalWrite(stepPin,LOW);
            delayMicroseconds(500);
          }
        }

delay(1000);
       }

lcd.begin(16,2);

lcd.setCursor(0,0);
       lcd.print("I/E=1:1TV=  BR= ");

lcd.setCursor(0,1);
       lcd.print(“ORDNANACEFACTORY”);

}
  }
     }

how to define exit and start new function.

The first thing that I would do is to make the actions taken when a match is found into functions with sensible names and call the appropriate one when a match is found. The key to exiting the call to a function is your use of statements such as

    while (strcmp(inputBuffer, "10BA") == 0)

Unless or until that is not true the same code will be executed. To stop the test returning true you need to change what is in inputBuffer.

If you set inputBuffer[0] to '\0' then the test will return false. You need to decide when to do this.

Is it :
after running the function once ?
after running the function a number of times ?
because of user input ?
because of some limit being reached ?

You decide

UKHeliBob:
The first thing that I would do is to make the actions taken when a match is found into functions with sensible names and call the appropriate one when a match is found. The key to exiting the call to a function is your use of statements such as

    while (strcmp(inputBuffer, "10BA") == 0)

Unless or until that is not true the same code will be executed. To stop the test returning true you need to change what is in inputBuffer.

If you set inputBuffer[0] to '\0' then the test will return false. You need to decide when to do this.

Is it :
after running the function once ?
after running the function a number of times ?
because of user input ?
because of some limit being reached ?

You decide

Because of user input:
The function should run continuously and exit this function with change of input 4 digit command from hex keypad and new while function should start according to the key input.

suppose while function of 4 digit input "10AB" is running. If "10BA" input is given, the "10AB" function should exit and "10BA" function should start.

Because of user input:

You need to structure the program differently in order to do that

Remember when I wrote

This is not the best way to do it

?
Now is the time to change to a different method that does not interfere with the free running of loop() whilst the user inputs a code

As its name suggests the waitForKey() function waits for user input and nothing else can happen until a keypress is registered. This is not what you want. Instead you need to use the getKey() function that looks for an input and if none is found it moves on so that your action function can continue to run

I suspect that if I try to describe this in detail and suggest that you try to write it then we will go back and forth with multiple replies here trying to get it to work. To get round this I will write a skeleton program and post it here later but I am note sure how soon

UKHeliBob:
You need to structure the program differently in order to do that

Remember when I wrote ?
Now is the time to change to a different method that does not interfere with the free running of loop() whilst the user inputs a code

As its name suggests the waitForKey() function waits for user input and nothing else can happen until a keypress is registered. This is not what you want. Instead you need to use the getKey() function that looks for an input and if none is found it moves on so that your action function can continue to run

I suspect that if I try to describe this in detail and suggest that you try to write it then we will go back and forth with multiple replies here trying to get it to work. To get round this I will write a skeleton program and post it here later but I am note sure how soon

UKHeliBob:
You need to structure the program differently in order to do that

Remember when I wrote ?
Now is the time to change to a different method that does not interfere with the free running of loop() whilst the user inputs a code

As its name suggests the waitForKey() function waits for user input and nothing else can happen until a keypress is registered. This is not what you want. Instead you need to use the getKey() function that looks for an input and if none is found it moves on so that your action function can continue to run

I suspect that if I try to describe this in detail and suggest that you try to write it then we will go back and forth with multiple replies here trying to get it to work. To get round this I will write a skeleton program and post it here later but I am note sure how soon

Thank you so much. I will wait for your reply sir.

Something for you to try

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte colPins[COLS] = {10, 11, 12, A4};
byte rowPins[ROWS] = {2, 4, 7, 8};

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

char inputBuffer[5];  //needs room for terminating '\0'
byte inputCount = 0;

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

void loop()
{
  static int functionToRun = -1;
  if (getInput() == true)
  {
    functionToRun = testInput();
    inputCount = 0;
    inputBuffer[0] = '\0';
  }
  runAFunction(functionToRun);
}

boolean getInput()  //read a key and add it to the array
{
  char key = keypad.getKey();
  if (key == NO_KEY)  //no keypress detected
  {
    return false; //entry not complete
  }
  else
  {
    inputBuffer[inputCount] = key;
    inputCount++;
    if (inputCount > 3)
    {
      inputBuffer[inputCount] = '\0'; //add termination
      return true;  //entry complete
    }
    else
    {
      //      inputBuffer[inputCount] = '\0'; //add termination
      return false ;  //entry not complete
    }
  }
}

int testInput() //test for matches
{
  int matched = -1;
  if (strcmp(inputBuffer, "ABCD") == 0)
  {
    matched = 0;
  }
  else if (strcmp(inputBuffer, "123A") == 0)
  {
    matched = 1;
  }
  return matched;
}

void runAFunction(int functionToRun)
{
  switch (functionToRun)
  {
    case 0:
      Serial.println("running function 0");
      break;
    case 1:
      Serial.println("running function 1");
      break;
    default :
      Serial.println("no function running");
  }
}

As before there are a number ways in which this could be improved and I strongly suggest that you put the code for each set of actions in their own named functions

UKHeliBob:
Something for you to try

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] =
{
  {‘1’, ‘2’, ‘3’, ‘A’},
  {‘4’, ‘5’, ‘6’, ‘B’},
  {‘7’, ‘8’, ‘9’, ‘C’},
  {’*’, ‘0’, ‘#’, ‘D’}
};

byte colPins[COLS] = {10, 11, 12, A4};
byte rowPins[ROWS] = {2, 4, 7, 8};

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

char inputBuffer[5];  //needs room for terminating ‘\0’
byte inputCount = 0;

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

void loop()
{
  static int functionToRun = -1;
  if (getInput() == true)
  {
    functionToRun = testInput();
    inputCount = 0;
    inputBuffer[0] = ‘\0’;
  }
  runAFunction(functionToRun);
}

boolean getInput()  //read a key and add it to the array
{
  char key = keypad.getKey();
  if (key == NO_KEY)  //no keypress detected
  {
    return false; //entry not complete
  }
  else
  {
    inputBuffer[inputCount] = key;
    inputCount++;
    if (inputCount > 3)
    {
      inputBuffer[inputCount] = ‘\0’; //add termination
      return true;  //entry complete
    }
    else
    {
      //      inputBuffer[inputCount] = ‘\0’; //add termination
      return false ;  //entry not complete
    }
  }
}

int testInput() //test for matches
{
  int matched = -1;
  if (strcmp(inputBuffer, “ABCD”) == 0)
  {
    matched = 0;
  }
  else if (strcmp(inputBuffer, “123A”) == 0)
  {
    matched = 1;
  }
  return matched;
}

void runAFunction(int functionToRun)
{
  switch (functionToRun)
  {
    case 0:
      Serial.println(“running function 0”);
      break;
    case 1:
      Serial.println(“running function 1”);
      break;
    default :
      Serial.println(“no function running”);
  }
}




As before there are a number ways in which this could be improved and I strongly suggest that you put the code for each set of actions in their own named functions

implemented my code with the above structure.

Function is not exit & new function not running with key input change. It is working continuously with present key function only. no breaking action happened.

Then I removed motor function and used only LCD display function.
then function working as per the requirement of changing present function to new function with change of key input.

forwarding the full code with motor and LCD display function.

pl.suggest whether I have done any mistake in including motor &LCD display function in

Switch function. I have verified many times but I could not find the mistake.

#include "Keypad.h"
#include "LiquidCrystal.h"

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8,9}; //connect to the column pinouts of the keypad

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

char inputBuffer[5];
byte inputCount =0;


const int stepPin = 10;

const int dirPin = 11;

const int enPin = 12;

LiquidCrystal lcd(22,23,24,25,26,27);

void setup(){

  pinMode(stepPin,OUTPUT);

  pinMode(dirPin,OUTPUT);

  pinMode(enPin,OUTPUT);

  digitalWrite(enPin,HIGH);

  }
  

  void loop()

      {
      static int functionToRun=-1;
      if (getInput()==true)
      {functionToRun=testInput();
       inputCount=0;
       inputBuffer[0]='\0';
      }
      runAFunction(functionToRun);
      }

      boolean getInput()
      { char key =keypad.getKey();
      if(key==NO_KEY)
      {return false;}
      else
       {inputBuffer[inputCount]=key;
       inputCount++;
       if(inputCount>3)
       {
        inputBuffer[inputCount]='\0';
        return true;  
       }
       else
       {
        return false;}
       }
      }
      

      int testInput()
      { int matched =-1;
        if(strcmp(inputBuffer,"10AB")==0)
            {matched =0;}
        else if(strcmp(inputBuffer,"10BA")==0)
            {matched =1;}
            return matched;
      }

      void runAFunction(int functionToRun)
      {
        switch(functionToRun)
        {
       case 0:
        lcd.begin(16,2);

        lcd.setCursor(0,0);
        lcd.print("I/E=1:1TV=  BR= ");

        lcd.setCursor(0,1);
        lcd.print("ORDNANACEFACTORY");
         
         digitalWrite(dirPin,HIGH);
             
         { for(int x = 0; x < 600; x++) 
         
           { digitalWrite(stepPin,HIGH);
             delayMicroseconds(2000);
             digitalWrite(stepPin,LOW);
             delayMicroseconds(2000);
           }
         }
        delay(1000);

        digitalWrite(dirPin,LOW);

         { for(int x = 0; x < 600; x++) 
         
           { digitalWrite(stepPin,HIGH);
             delayMicroseconds(2000);
             digitalWrite(stepPin,LOW);
             delayMicroseconds(2000);
           }
         }
        delay(1000);
          
        break;

        case 1:
        lcd.begin(16,2);

        lcd.setCursor(0,0);
        lcd.print("I/E=  TV=  BR= ");

        lcd.setCursor(0,1);
        lcd.print("ORDNANACEFACTORY");


         digitalWrite(dirPin,HIGH);
             
         { for(int x = 0; x < 800; x++) 
         
           { digitalWrite(stepPin,HIGH);
             delayMicroseconds(1000);
             digitalWrite(stepPin,LOW);
             delayMicroseconds(1000);
           }
         }
        delay(1000);

        digitalWrite(dirPin,LOW);

         { for(int x = 0; x < 800; x++) 
         
           { digitalWrite(stepPin,HIGH);
             delayMicroseconds(500);
             digitalWrite(stepPin,LOW);
             delayMicroseconds(500);
           }
         }

        delay(1000);
        break;    
      
        default:
        lcd.begin(16,2);

        lcd.setCursor(0,0);
        lcd.print("idle");
         
        } 
      }

I see that you did not take my advice to move your action code to named functions, but that is not the problem. The problem is your use of delay(), during which nothing else, including reading the keypad can happen. This is compounded by the use of a for loop with 600 steps during which the keypad will not be read

You need to restructure your program. Once functionToRun has been given a value then the code in that case will be called each time through loop() and you can take advantage of that by arranging that each time the case code is used the stepper moves one step. Do this by using a counter variable much as you would in a for loop. For now, remove the delay()s as well

So, you plan is :

When functionToRun changes its value set a counter variable to 0
In the case code move the stepper one step and increment the counter variable then break out of the case
Do this until the counter reaches 600 or 800
If you want the stepper to move back and forth continuously then when the counter reaches 600 or 800 set it back to 0 and change the stepper direction
You can deal with the delay()s once the above has been implemented