How do I interface a microcontroller with PC USB so that I can imitate the keystrokes and movement of keyboard and mouse. I've heard of software fixes, but is there any IC which can mimic the keystrokes after getting input from the microcontroller?
Asked
Active
Viewed 2,155 times
1
-
I doubt there is a ready-made IC available (except for the obvious: a keyboard controller, salvaged from a keyboard!), but you can program any USB-capable microcontroller to do this. – Wouter van Ooijen Jul 14 '14 at 15:48
-
Simplest option is an Arduino Leonardo. Has it all ready done for you. – Majenko Jul 14 '14 at 15:50
-
If planning to use arduino, read this:[Mouse and Keyboard libraries](http://arduino.cc/en/Reference/MouseKeyboard) – nidhin Jul 14 '14 at 15:59
-
is there any bluetooth module that can do the same thing – seetharaman Jul 14 '14 at 16:41
-
This previous question might help you with Bluetooth: http://electronics.stackexchange.com/questions/514/cheapest-simplest-way-to-implement-a-bluetooth-keyboard-mouse?rq=1 – akellyirl Jul 14 '14 at 16:51
1 Answers
2
An Arduino based on the ATmega32u4 can do this, performing the function of both the microcontroller and keyboard/mouse emulator.
For example: Arduino Leonardo, Yun or Arduino Micro.
The Arduino Micro is nice because of its form factor.
The library support for USB keyboard and mouse emulation is readily available to make a project like yours very easy.
This code snippet opens a new document by emulating CNTRL-N
// new document:
Keyboard.press(ctrlKey);
Keyboard.press('n');
delay(100);
Keyboard.releaseAll();
// wait for new window to open:code

akellyirl
- 4,117
- 1
- 16
- 30
-
So how exactly does this work? I looked at the [schematic](http://arduino.cc/en/uploads/Main/arduino-micro-schematic.pdf) for the Micro and I don't see an FTDI or any sort of USB -> UART converter IC. Also, wouldn't sending the keystrokes over USB from a PC require software run on the host? – sherrellbc Jul 14 '14 at 16:02
-
how can i do the same without arduino.. like if i send a hex byte from uP it sends corresponding key stroke to pc.. thanks – seetharaman Jul 14 '14 at 16:02
-
USB is native on the ATmega32u4. Firmware needs to run on the Arduino. USB KBD/Mouse Driver would be present on PC already. – akellyirl Jul 14 '14 at 16:03
-
Ah, I forgot some of the newer AVR have native support. This is really quite an interesting thing to do. – sherrellbc Jul 14 '14 at 16:08
-
How can I do this with minimal software usage. Im already running a lot of code and i cant spare much of my processors time. Is there any way to do this Im clueless right now, can somebody tell me where to look? – seetharaman Jul 16 '14 at 15:10
-
@seetharaman - have you looked at the links to the keyboard library which were posted yesterday yet??? If its still too big, using a large chip would likely be the most effective, but you can consider using one chip for USB and another for your program. An Uno with the USB micro reprogrammed might be an option, but probably inferior to a larger all-in-one device (possible ARM rather than AVR) – Chris Stratton Jul 16 '14 at 15:52
-
@ChrisStratton I saw that library. I'm thinking of that as a last option. – seetharaman Jul 17 '14 at 01:37
-
@ChrisStratton https://www.sparkfun.com/products/10253. I found this link, and was hoping to find a similar ic or module for the usb thing. – seetharaman Jul 17 '14 at 01:41
-
You've already been given a link to such a solution, but inexplicable want to treat it as your "last option". There's very little practical difference between a micro mask-rom'd from the factory to perform a particular function, and a *generic* micro flashed with available software to perform that function. One vendor's "fixed-function" USB-serial part actually turned out to just be one of their generic micros relableled and flashed at the factory - it was still user-reprogrammable! – Chris Stratton Jul 17 '14 at 15:42
-
@ChrisStratton "One vendor's "fixed-function" USB-serial part actually turned out to just be one of their generic micros relableled and flashed at the factory - it was still user-reprogrammable!" I thought if i could find robust ic then i wouldnt have to worry about the keyboard part.. right? Now decided to go with a software implementation. thanks – seetharaman Jul 18 '14 at 17:33