Keypad controlling Stepper

Hello everyone,
I know I am a newbie to all of this, but I am currently working on a project that includes a stepper motor, a 4x4 keypad, and an Arduino Mega 2560. I am at the stage in my project where if I press any key on my keypad the stepper motor will go for a 100 steps clockwise. My goal for the project is when I press a specific key (for example key "1") the motor will go for 100 steps clockwise and then when I press another key (for example key "2") the motor will stop immediately. Same thing for the motor running counter-clockwise (press key "3" to make it go counter clockwise, but still have key "2" stop the program). I am very confused and would greatly appreciate any help!

My goal for the project is when I press a specific key (for example key "1") the motor will go for 100 steps clockwise and then when I press another key (for example key "2") the motor will stop immediately.

If the code alternates between looking for a key press and stepping, no problem. If the code does all the stepping, and then looks for a key press, problem.

I am very confused and would greatly appreciate any help!

So, let's see what you have.

PaulS:
If the code alternates between looking for a key press and stepping, no problem. If the code does all the stepping, and then looks for a key press, problem.
So, let's see what you have.

void setup()
{
// set the motor speed at 30 RPMS:
myStepper.setSpeed(30);

// Initialize the Serial port:
Serial.begin(9600);
}

void loop()
{
char keypressed = myKeypad.getKey();
if (keypressed != NO_KEY)
{
Serial.print(keypressed);
Serial.println(" Forward"); // Step forward 100 steps:
myStepper.step(-100);
delay(0);
}

}

This is my code for the void setup and void loop. I defined and set all my integers properly.

bemur22:
This is my code for the void setup and void loop. I defined and set all my integers properly.

For the future post a complete program that we can compile on our Arduino.
And use the code button </> so the code looks like this and can be selected

The code you have shown completes all 100 steps before it can check for another button press. You need to re-write it so that it only moves one step between button checks. Use a variable to keep track of how many steps the motor has moved.

...R
Stepper Motor Basics
Simple Stepper Program

Thanks so much for the help! I tweaked my code a bit and now it works exactly how I need it to.