Keypad integration with Stepper motor While() issues

I am using a keypad (https://www.amazon.com/Matrix-Membrane-Switch-Keyboard-Arduino/dp/B015M1CEIC/ref=sr_1_2_sspa?ie=UTF8&qid=1518022496&sr=8-2-spons&keywords=arduino+keypad&psc=1)

to control a stepper motor and sucessfully have the motor spinning mostly in the way I would like with buttons coreesponding to pre set steps for various rotational outputs. I would also like to figure out how to incorporate a function where the motor runs WHILE a button is being held down.
I have found code examples online that acchomplish this with a statement like

void loop() { 

   if (digitalRead(button1) == LOW || digitalRead(button2) == LOW) { // ako ni jedan taster nije pritisnut
  digitalWrite(step_pin, LOW);
  digitalWrite(step_pin, LOW);
   }
  
  
 if (digitalRead(button1) == LOW && digitalRead(button2) == HIGH) { // ako je taster 1 idle, a taster 2 pritisnut
    digitalWrite(dir_pin, LOW); // move in the LOW direction
    digitalWrite(step_pin, LOW);
    delay(3);
    digitalWrite(step_pin, HIGH);
    delay(3);
    
  } else if (digitalRead(button1) == HIGH && digitalRead(button2) == LOW) { // ako je taster 2 idle, a taster 1 pritisnut
    digitalWrite(dir_pin, HIGH); // move in HIGH direction
    digitalWrite(step_pin, LOW);
    delay(3);
    digitalWrite(step_pin, HIGH);
    delay(3);
  }
  
  
}

The problem I has is that the code isnt functioning in a similar way for me when using the keypad library and - if (keypressed ==‘1’){} statement for if button is pressed run motor until it is not pressed.
When trying a while (keypressed == ‘1’) {} and not defining step count the motor just runs continuously.

#include <Key.h>
#include <Keypad.h>

#include <Encoder.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h> 

int dirpin = 11;
int steppin = 12;


Encoder myEnc(2, 3);    //A and B signal wires wired to Signal contact Digital pin 0 and 1 respectively

LiquidCrystal_I2C lcd(0x27,20,4);





int Speed1 = 800;   //Measured cuts
int Speed2 = 800;  //Small Movements





const byte Rows= 4; //number of rows on the keypad i.e. 4
const byte Cols= 4; //number of columns on the keypad i,e, 3

//we will definne the key map as on the key pad:

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

//  a char array is defined as it can be seen on the above


//keypad connections to the arduino terminals is given as:

byte rPins[Rows]= {0,10,4,5}; //Rows 0 to 3
byte cPins[Cols]= {6,7,8,9}; //Columns 0 to 3

// command for library for keypad
//initializes an instance of the Keypad class
Keypad kpd= Keypad(makeKeymap(keymap), rPins, cPins, Rows, Cols);

void setup()
{

  
     Serial.begin(9600);  // initializing serial monitor
     pinMode(dirpin, OUTPUT);
     pinMode(steppin, OUTPUT);

}
  


//If key is pressed, this key is stored in 'keypressed' variable
//If key is not equal to 'NO_KEY', then this key is printed out


void loop()
{
    int i;
    
     char keypressed = kpd.getKey();
     if (keypressed != NO_KEY)
     { 
          Serial.println(keypressed);
        
          
   
      
      
     if (keypressed =='1'){
        
        
         digitalWrite(dirpin, HIGH);    // Set the direction.
            for (i = 0; i<1627; i++)       // Iterate 
          {
            digitalWrite(steppin, LOW);  
            delayMicroseconds(Speed1);     
            digitalWrite(steppin, HIGH); // step.
            delayMicroseconds(Speed1);      // This delay time is close to top speed for this
          }                              // particular motor. Any faster the motor stalls.
            Serial.println(" 40 ");
            digitalWrite(dirpin, HIGH);    // Change direction.
            delay(500); //Pause to clear
      }

             
    
     }
	 
}

I am not familiar with the keypad library but I imagine it is possible to detect when a key is pressed and when it is released.

For continuous operation I would set a variable (let's call it rotateContinuous) to true when the key is pressed and set it back to false when the key is released.

Then the code for running the motor can check that variable to decide what to do.

...R

For some reason that logic doesnt play nice with they keypad.h I will test and post results

Perhaps the "bool isPressed(char keyChar);" function will help.

void loop() {
    int key = kpd.getKey()

    switch (key) {
    case 'A':  // Jog Left
            digitalWrite(dirpin, HIGH);
            while (kpd.isPressed(key)) {
                digitalWrite(steppin, LOW);  
                delayMicroseconds(Speed1);     
                digitalWrite(steppin, HIGH); // step.
               delayMicroseconds(Speed1);
           }
           break;

    case 'B':  // Jog Right
            digitalWrite(dirpin, LOW);
            while (kpd.isPressed(key)) {
                digitalWrite(steppin, LOW);  
                delayMicroseconds(Speed1);     
                digitalWrite(steppin, HIGH); // step.
                delayMicroseconds(Speed1);
           }
       break;
    }
}

If I'm not mistaken, Keypad.getKey returns 0 if no key is pressed.

That would be another way to check.