control stepper motor with computer keyboard using arduino

I'm pretty new to arduino and processing, but I want to control a stepper motor using a computer keyboard. What I had in mind is when I press down a button such as "right button" then the motor would turn to the right and keep moving till I press up, or when I press "left button" then the motor would move to the left until I press up.I searched for this idea and all what I got is for the servo motor. Can anyone help me with the schismatic of the idea and the code?

There's a bunch of posts discussing how to do that on the forum but I don't remember where they are. You'll just have to search on the forum.

You didn't mention whether your driver uses STEP/DIR or IN1,IN2,IN3,IN4 signals. We would need to know that.

You'll need to use a different terminal program than the one included with the IDE. The Arduino terminal requires you to use the "enter" key to send text to the Arduino.

You'll need to use a different terminal program than the one included with the IDE. The Arduino terminal requires you to use the "enter" key to send text to the Arduino.

That's a good point. I didn't even think of that. I made a custom keyboard for my Senior Project at DeVry. I found a very expensive all metal custom ATE keyboard at a surplus store for $50 . It had a round CANON plug on the end and output TTL serial so I added a UART to convert the serial to parallel
and changed the connector to a parallel connector. I then added an EEPROM addressed by the parallel output of the UART. I then made a list of every value (in HEX) sent by every key. I created a memory-mapped I/O for the EEPROM by storing the standard ASCII value I wanted at the addresses (key values) sent by the keyboard. Since it was a multi thousand dollar custom keyboard with groups of different colored keys, the values sent were not always the ascii values I expected and there were many more keys than a standard keyboard. By creating a memory map of the keys, I could store the desired value in the address sent by the keyboard and thus was able to convert a group of custom ascii values sent in serial to a standard set of values sent in parallel. I admit it was probably more work than it was worth
but I wanted the "WOW" factor that the keyboard evoked when you saw it. It was like "holy crap ! will you look at that keyboard ! It looks like something from WAR GAMES !".. ;D

Take a look at this sketch.
It reads the keyboard and looks for "f" [FORWARD]
or
"F" [REVERSE]

 byte directionPin1 = 7;
// byte directionPin2 = 4;
// byte directionPin3 = 6;
// byte directionPin4 = 8;
// byte directionPin5 = 10;
// byte directionPin6 = 12;
byte stepPin1 = 8;
// byte stepPin2 = 5;
// byte stepPin3 = 7;
// byte stepPin4 = 9;
// byte stepPin5 = 11;
// byte stepPin6 = 13;
int numberOfSteps = 5000;
byte ledPin = 14;
int pulseWidthMicros = 50;  // microseconds
int millisbetweenSteps = 10; // milliseconds

  void setup()
  {
     Serial.begin(9600);
     
     for (int pins = 1; pins < 13; pins++)
     {
       pinMode(pins, OUTPUT);
     }
  }
  
  void loop()
  {
    if (Serial.available() > 0)
    {
      int inByte = Serial.read();
      
      switch (inByte)
      {
        case 'f':  {   
                      Serial.println("Starting Stepper Motor 1 CW");
                      digitalWrite(ledPin, LOW);
  
                      delay(1);

                      pinMode(directionPin1, OUTPUT);
                      pinMode(stepPin1, OUTPUT);
                      pinMode(ledPin, OUTPUT);
                      
                      digitalWrite(directionPin1, HIGH);
                      for(int n = 0; n < numberOfSteps; n++) 
                      {
                        digitalWrite(stepPin1, HIGH);
                        delayMicroseconds(pulseWidthMicros);
                        digitalWrite(stepPin1, LOW);
    
                        delay(millisbetweenSteps);
    
                        digitalWrite(ledPin, !digitalRead(ledPin));
                      }
                     
                     delay(100);
                    }
                    break;
        
        case 'F':   {
                      Serial.println("Starting Stepper Motor 1 CCW");
                      digitalWrite(ledPin, LOW);
  
                      delay(1);

                      pinMode(directionPin1, OUTPUT);
                      pinMode(stepPin1, OUTPUT);
                      pinMode(ledPin, OUTPUT);
                      
                      digitalWrite(directionPin1, LOW);
                      for(int n = 0; n < numberOfSteps; n++) 
                      {
                        digitalWrite(stepPin1, HIGH);
                        delayMicroseconds(pulseWidthMicros);
                        digitalWrite(stepPin1, LOW);
    
                        delay(millisbetweenSteps);
    
                        digitalWrite(ledPin, !digitalRead(ledPin));
                      }
                     
                     delay(100);
                    }
                    break;
                    
        
                    
         default:   {
                    }
                    break;
      }
    }
  }

I try not to challenge solutions proposed by others, but the code in Reply #4 uses delay() and that is completely unsuitable if the Arduino is to be responsive to button messages coming from the PC.

There needs to be a function that causes the stepper to move according to th value in a variable. Something like this pseudo code

if (cmdVar == 'F' ) {
   direction = forward;
   moveOneStep());
}
else if (cmdVar == 'R') {
  direction = reverse;
  moveOneStep();
}

and there needs to be a separate function that recieves data from the PC and updates the contents of cmdVar. See Serial Input Basics

It would probably be easier from the user's perspective to write a PC program to detect the key presses and send suitable messages to the Arduino.

You do NOT want to send a continuous stream of 'F's when the F key is pressed. You just want to send a message when the key is first pressed and another message when the key is released.

...R