Go Down

Topic: Arduino as Keyboard (Read 4440 times) previous topic - next topic


Hey all,

I've built a custom input device, similar to a one-handed keyboard, around the arduino.  Now I'm trying to figure out how can I get the PC to recognize the arduino as a keyboard, and communicate keystrokes.  

Right now I'm sending data over serial to an application on the PC, when then generates keyboard events.  This approach is obviously not optimal, plus it doesn't work when DirectInput apps, etc, are running.

Any ideas?



One idea that comes to mind is to hack an actual keyboard.  Some use matrices where it scans all the buttons row by row and senses if any of the columns are connected.  Maybe you could have the arduino put voltage to the columns when it senses voltage from the right row?


To the best of my knowledge, because of the hardware, the computer will only recognize the usb connection on the arduino as a serial link, not as a HID.

I have hacked a keyboard before using transistors to toggle multiple key presses (such as Ctrl + anykey) which worked remarkably well. Unfortunately I don't have any of that project documented but there is some good information about that technique on this page http://blogs.msdn.com/ntdebugging/archive/2008/10/10/unlocking-some-puzzles-requires-building-a-better-key-board.aspx.


I think it would not be difficult for an Arduino to emulate a PS/2 keyboard output.  If I recall correctly, this is a 0 - 5VDC serial interface.

You could then cut up a PS/2 keyboard cable (you should be able to find an extension cable) to get a cable with a male PS/2 (actually a DIN-style) plug.

That connector would plug into a PS/2 to USB converter available for about $US5.  Here's an example:  http://www.emtcompany.com/products/adapters/ps2usb-ps2-to-usb-adapter.htm.



Sep 10, 2009, 02:23 am Last Edit: Sep 10, 2009, 02:25 am by TBAr Reason: 1

If you haven't seen it yet, http://www.arduino.cc/playground/ComponentLib/Ps2mouse has a link to a library at the very bottom of the page. Scroll down until you get to "Emulating a PS2 device".

The library can be used to make an Arduino act as a PS2 mouse or a PS2 keyboard.


Thanks for the responses.

I have previously used the hacked keyboard approach for other input devices, mainly arcade controllers which have only a few buttons/switches.  The problem with that is that representing a standard 101 key keyboard requires a lot of pins (you'd have to control a 10x11 matrix at least).  I'm sure there are clever ways to reduce the pin count, but I'm looking for a more direct approach.  

Emulating a PS2 device looks interesting.  I'll play around with the ps2dev library linked earlier.

Thanks again.


I haven't seen any example of using an Arduino as a keyboard, but have seen several projects that use the various Atmel chips plugged into the USB port acting as a keyboard etc.

Do a search in Google for "AVR HID" (HID = Human Interface Device, which is the category keyboards belong to). It should return a number of examples, and you might be able to adapt the code from one of these, or turn your design into a standalone device rather than being an arduino.


OlJanx, did you get the ps2dev to work?
Because I can't figure out what to do with it.. I would appreciate some help.


For the record http://code.rancidbacon.com/ProjectLogArduinoUSB includes code and a shield design for the Arduino acting as an USB keyboard. :)


Go Up