How to control motors with a keyboard

Is it possible to control NEMA17 stepper motors with a keyboard so that when a key is pressed, the motor will rotate until the key is released?

What sort of keyboard?

Welcome to the forum

Is the keyboard attached to the Arduino or a PC ?

Its a Dell keyboard with a USB

I have been trying to connect the keyboard directly to the Arduino.

Yes, most likely.

Is the keyboard on the PC or a keypad (3x4 or 4x4)?

What Arduino? What stepper driver?

Please read the forum guidelines. That post has information on what we would like to know in order to help you.

Do you have to use a keyboard ?
Would a simple pushbutton be acceptable ?

Which Arduino. Does it have native USB like a Leonardo?

Which Arduino?

It is a full PC keyboard, I am using an Arduino Mega 2560, and I am using tb6600 stepper motor drivers to control the stepper motors.

Can you use a Leo to read a USB device ?

I need to use many buttons and I was hoping I could use a keyboard that I already had instead of making a circuit with multiple pushbuttons.

My mistake. Leonardo can act as a USB keyboard (send keystrokes to PC), but, apparently, cannot read a USB keyboard.

How many ?

How many buttons? A 4X4 keypad has 16 buttons and is pretty easy to interface, though it takes 8 pins.

You can bring the pin usage down to 2 pins using an I2C expander with the 4x4 keypad.
https://www.hackster.io/mitov/i2c-matrix-keypad-with-pcf8574-pcf8574a-gpio-and-visuino-dbf72c

I'm not sure exactly how many but I need to control about 25 motors with a button for both directions of rotation.

What sort of application is this for ?

How about a method of selecting which motor is to be controlled then, with the motor selected, a button for each direction ?

I was going to control a robot by controlling many stepper motors simultaneously.

A maximum of 10 at the same time at most, presumably :grinning:

I might be able to work with only 10 at the same time. How exactly would I connect the keyboard to the Arduino?