Go Down

Topic: Make arduino control windows mouse and keyboard? (Read 6033 times) previous topic - next topic

banditmatt

Hi.  Is there a way to make the arduino control the mouse and keyboard in windows?  for instance, use a pot to control mouse x movement, and another to control y movement, and a series of buttons for certain keyboard buttons?  The reason I'm asking is I'm trying to make a custom controller to play computer games.  It would be great if the solution could be done in processing.  Thanks in advance.

chrome123

I'm pretty sure a mouse just sends a stream of data so i guess it is possible (a mouse has a pic in it) keyboard should have the same basic idea to it no?

MikMo

There's an example of interfacing a PS2 mouse in the playground. If thai could be any help.

As for the keyboard, i don't think it's very easy.

You could scavenge the (very small ) circuit board from a USB keyboard and hack into the matrix and have arduino simulate key presses by connecting the proper rows / coloums of the matrix.

lilpunk1302

Quote
There's an example of interfacing a PS2 mouse in the playground. If thai could be any help.

As for the keyboard, i don't think it's very easy.

You could scavenge the (very small ) circuit board from a USB keyboard and hack into the matrix and have arduino simulate key presses by connecting the proper rows / coloums of the matrix.


Yeah, but it's a pain mapping out the matrix.

Depending on what's faster(Ardy or KB), why not plug the PS2 port pins directly into the arduino, push every key then have Ardy send what pins get triggered.

Basically a diy packet scanner.

Check just have it resend those packets as needed.

MikMo

The ps2 port uses something that resembels a serial protocol, so that would not work.
But you could find a description of the protocol (like someone did with the PS2mouse) and implement it on Arduino

mem

One way you can do this is to send serial commands to a pc program and have that program inject mouse or keyboard events using whatever native api is available. In Java, the API is :
http://java.sun.com/j2se/1.3/docs/api/java/awt/Robot.html

follower

Depending on your preference, needs and skill you could try either a PS/2 or USB based solution.

Do you want a USB or PS/2 device?

--Phil.

banditmatt

Quote
One way you can do this is to send serial commands to a pc program and have that program inject mouse or keyboard events using whatever native api is available. In Java, the API is :
http://java.sun.com/j2se/1.3/docs/api/java/awt/Robot.html

Yes, this is exactly what I was looking to do.  Is there a way I could use these commands in processing?  I know nothing about java.

lilpunk1302

I know there's a way to *send* commands from processing,

http://www.arduino.cc/en/Tutorial/Dimmer

Haven't worked with it at all though so don't know if you can receive.

banditmatt

Quote
I know there's a way to *send* commands from processing,

http://www.arduino.cc/en/Tutorial/Dimmer

Haven't worked with it at all though so don't know if you can receive.


There absolutely is a way to send and receive commands in processing via serial.  I have no idea where a command would be sent in a computer to say "press the "A" key" without literally plugging a cord into the keyboard port.  There has to be a way for a computer to internally generate mouse and keyboard commands, right?

lilpunk1302

Bleh, sorry, "explained" it wrong(well, didn't at all)

That guide shows you how to have Processing read the mouse coordinates and send them over serial.

Granted, generating them from serial input would be much harder, but you;re already half way there.

macegr

If you can get the AVR-USB code running on your Arduino (it's been done already, in these forums) you will have a way of sending keyboard or mouse input. Last year I designed a device that sits on a USB port and pretends to be a keyboard, mouse, or joystick. Then you'd send commands to it over I2C. It uses the AVR-USB library. I put it into a model airplane and used an accelerometer to sense roll and pitch to control a joystick in a flight sim game. You plug the device into any computer and it appears as a generic joystick.
Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

#12
Jun 15, 2008, 11:53 am Last Edit: Jun 15, 2008, 12:08 pm by bens Reason: 1
Quote
If you can get the AVR-USB code running on your Arduino (it's been done already, in these forums) you will have a way of sending keyboard or mouse input. Last year I designed a device that sits on a USB port and pretends to be a keyboard, mouse, or joystick. Then you'd send commands to it over I2C. It uses the AVR-USB library. I put it into a model airplane and used an accelerometer to sense roll and pitch to control a joystick in a flight sim game. You plug the device into any computer and it appears as a generic joystick.

I don't have too much experience with this, but I believe there's a pretty substantial difference between emulating a USB device and emulating a USB host (which is what would be required to connect to a USB device such as a mouse or keyboard).  But I'm not speaking with any authority here; I could be totally wrong.

- Ben

mem

If you are familiar with a windows programming language, it really is much easier to write something that receives serial commands from the arduino and injects them using the appropriate programming interface for your language

The low level windows API function to insert keyboard and mouse events into the input stream is called SendInput:
http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx

But search the documentation for your favorite programming language for how best to call this.

macegr

Quote
Quote
If you can get the AVR-USB code running on your Arduino (it's been done already, in these forums) you will have a way of sending keyboard or mouse input. Last year I designed a device that sits on a USB port and pretends to be a keyboard, mouse, or joystick. Then you'd send commands to it over I2C. It uses the AVR-USB library. I put it into a model airplane and used an accelerometer to sense roll and pitch to control a joystick in a flight sim game. You plug the device into any computer and it appears as a generic joystick.

I don't have too much experience with this, but I believe there's a pretty substantial difference between emulating a USB device and emulating a USB host (which is what would be required to connect to a USB device such as a mouse or keyboard).  But I'm not speaking with any authority here; I could be totally wrong.

- Ben


He wants to connect an Arduino to a PC and allow the Arduino to control the mouse pointer and keyboard input. Not connect a USB keyboard/mouse to the Arduino. Although that is also very possible to do with FTDI's Vinculum chip.
Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Go Up