Emulating a keypress

I apologize if I placed this into the wrong forum.

I am relatively new to Arduino but am in the midst of a large project that I will be using it for. I have to take the values of sensors and then send this information into a game (Second Life). I've determined the quickest way to do this is to have Arduino emulate one or two key presses (press the W key if the senor returns data within this range, E if it is within this range, etc).

The problem is I am finding very little information on how to properly do this. I was wondering if anyone can lend me some insight on how to get it to emulate the keypress.

If you think this is a bad idea, of course feel free to suggest another way to send the data through!

Thank you,


check this:


One way to interface basically anything to a computer by "keypresses" is to hack an old USB keyboard.

In a USB keyboard there's a tiny little printed circuit board with two groups of connectors that are normally connected to all the keys on the keyboard. These connectors are organised in a matrix of X rows and Y coloumns. By shorting one connectore from the rows group to one connector in the coloumns group you simulate a key press. It's just a matter of trial and error to find out which connectors to short together to produce any kepress you like.

Unfortunately different USB keyboards have different layout of the connectors, so it is not possible to give any specific advice on which connectors to use.

When you know which connectors to short to produce the desired keypresses, you can hook a 4066 Quad analog switch IC up to 4 digital pins on the arduino board and the 4 switces on this IC can be used to short 4 connector pairs in the USB keyboard PCB, and in that way simulate 4 different keypresses. By closing more of the 4066 switches at the same time you can even simulate things like "SHIFT + F5" or whatever key combination you like.

This method can also be used to build alternative input devices that can replace an ordinary keyboard. You can for instance build a box with 4 large switches that will allow people to press only 4 of the keys on a keyboard connected to a computer used to control some part of an installation or whatever.

MikMo http://www.mikmo.dk

EDIT: Be aware that by using the above method you can produce key press combinations that are not normally possible or allowed, this might crash some computer programs i think. In the simple tests i have made until now this has not happend.

Yeah I was thinking along the lines of breaking open a keyboard but I’m looking for a way to finesse it. I’m thinking about wiring a serial port to individual pins and just have a each pin on a serial cable represent a “key”. A visual basic program would then read the input from the serial port and emulate the keypress. But right now I’m looking for an easier already made method.

Thanks for the replies so far, and I’d love to find out more if you guys know of any.

How many different keys do you need to emulate ?

Just single keystrokes or combinations ?

Just single key strokes- like pressing the q key or w key.


If you don't fancy the idea of breaking open an USB keyboard, you can always use a keyboard module like this one:

http://www.ultimarc.com/ipac1.html http://www.ultimarc.com/ipacve.html (economy USB model)

Basically it is a bunch of switches and it shouldn't be a problem to interface it with a Arduino.

A more complicated option (but very powerful) is to build a Processing sketch with the Java Robot class. Robot is a class to control mouse and keyboard events:


The arduino can talk to Processing which sends key presses to the host.


Hi, here is another hardware solution which does not use the Arduino: http://www.codemercs.com/KeyWarriorE.html Its one of the chips you might find in USB-keyboards. The good part of the story is that its available in DIP-packages too, and the datasheet for the chip also provides a schematic.


After a lot of research I believe I found a solution. I will have the digital I/O pins wired into a serial port. A VB program is simple enough to make with premade classes that will read the serial port and then depending on what is on and off I can trigger a keypress! I will post whether or not if this is a success as it may be the easiest way for Arduino to emulate keypresses.