Mouse/Keyboard emulation in C# and/or Windows?


I'm curious, what is the easiest way to get my Arduino (connected to PC of course) emulate mouse or keyboard? Let's say I'll connect touchpad to Arduino and I want to use it instead my mouse (or with it).

I can read touchpad's signals with Arduino, send them to PC, then receive them with PC program, but what's next? Let's assume I don't want to write my own mouse/keyboard driver :)

Is MSDN method the easiest? Or maybe there's some sort of Arduino-compatible solution already? Maybe Arduino connected to COM (via FTDI) port can be identified by system as additional mouse/keyboard like standard device, which doesn't need any drivers?

Let's assume I don't want to write my own mouse/keyboard driver

It can't be done, then.

The FTDI chip on the Arduino makes the UDB port appear to the PC as a COM port, making the Arduino appear as a serial device.

Serial devices need drivers - something to map instructions from the PC to serial data, and to map the serial data back to instructions to the PC.

I agree, but:

  1. There are software methods (like the one from MSDN) for emulating hardware, which I can implement in my own program. Just wanted to know, if there is simplier and faster method.

  2. What about serial mice which do not need drivers? There are some, AFAIR, working in Win. I assume there is some kind of "standard" communication protocol or handshake which identify the device as a mouse?

If you want to communicate only between your application and the "Arduino as a mouse" that is different from making the Arduino act like a mouse.

There are messages that are sent by the mouse driver when the device it is monitoring changes position or a button on it is pressed or released. If you are trying to make the Arduino act as a mouse in a general sense, you need to have an application on the PC read the serial data and generate those messages. That application, which runs all the time, is a device driver.

If you only want the Arduino to act as a mouse for your application, then the process is much simpler. Your application registers a handler to be invoked whenever there is serial data to be processed. That callback would then follow the process in the MSDN article to generate the mouse move/button press events that your application (perhaps indirectly) subscribes to.

The Arduino would need to be programmed to send serial data whenever the "mouse moved".

What about serial mice which do not need drivers?

There is no such thing. Every serial device needs a driver. There are some generic drivers that some operating systems supply that sometimes work well enough.

For a serial device to be understood by a generic driver, it needs to send specifically formatted data to the serial port, at specific speeds, and respond to specific requests.

I don't know where you would find out what specific data at what specific speed to enable a generic Windows mouse driver to understand/drive your "mouse".

As you were replying, I found out I put the post in wrong subforum - it was supposed to be in Interfacing.

Maybe that's why I wasn't understood at first (and maybe it was because my English isn't very good :)). I was rather asking if there's already some sort of solution for that.

But there's a good side - if there's nothing "done" yet, then I have a brand new idea for using Arduino :) Thanks for replies.

WRonX, the playground has a library that will let your Arduino act as a PS/2 mouse. Have a look at Scroll all the way to the bottom of that page to get to the topic "Emulating a PS2 device".

If you have a PS/2 mouse port on your PC you are ready to rig up a cable and try it. Otherwise you may be able to rig up a cable and connect it through a PS/2-to-USB adapter between your Arduino and your PC.

Thanks, I'll start with it.