How can i press a key on my keyboard so that its activates a motor ?

Im working on a project and I want to hit a key on my laptop and have a DC motor go off, I already programmed moving servos with mouse movement but Im finding it hard to get this to work.

How are you sending mouse movement details to the (presumed) Arduino?

I wrote code on the arduino and on visual studio using a win form so i move my mouse side to side and its moves left and right with a servo on the bottom and then up and down changes tilt on the top servo

(deleted)

Im just struggling with the code for pressing a key on my keyboard and that starting a motor and stoping when i release the key

You need to look at the visual studio end of things for reading the keyboard press, never used it

Presumably you then send a signal dependant upon whether the key is pressed or not over the RS232 link and the Arduino then acts upon it .

Can you be more specific where exactly you are stuck ? On VS or Arduino ?

Post your code. In code tags please.

i dont have code for this part of the project i just need help with code to press a key and a DC motor to run, if someone can help me that would be great

Just to be clear, you're asking for code for the PC end, to detect a PC keyboard press in VS, in the Arduino forum?

Or are you asking how to catch the PC's output at the Arduino end and get the motor to react?

Im asking for code so i can press a key and have the arduino send a signal to have the DC motor move

padraigBruh:
Im asking for code

PC (VS) code or Arduino code?

If you want PC code I'd venture to suggest you're asking in the wrong place.

If Arduino code, you would need to describe what's being received from the PC (and through what medium) as well as what it means to "have the DC motor move" along with details of the hardware connection between the Arduino and the motor.

(I'm surprised that if you wrote code to do something with a PC mouse and an Arduino servo, that you can't do the same for the keyboard / dc motor.)

padraigBruh:
Im asking for code so i can press a key and have the arduino send a signal to have the DC motor move

I'm just curious how many more times you will repeat this until you figure out the problem is not an arduino thing.

So you show us all your code (PC and Arduino) that moves servos based on mouse movements and we'll work from that.

Steve

I have an arduino UNO and i want to press a key/ click my mouse to start a DC motor

You write a program for the PC.

(deleted)

didnt get help just got asked about other code that wasnt related, Im new and i want help either help or leave me alone

I've merged your cross-posts @padraigBruh.

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

(deleted)

padraigBruh:
didnt get help just got asked about other code that wasnt related, Im new and i want help either help or leave me alone

You will not get very far with this attitude. You were asked to post your code; it does not matter if you consider it relevant or not. At least we would more than likely have been able to determine the language that you're using for the WinForm.

Anyway, look at the form's KeyPress, KeyDown and KeyUp events.