Saturday, January 11, 2014

Software only Arduino keyboard emulator

I'm a proud owner of an Arduino Duemilanove, which unfortunately can not act as a USB keyboard without extra hardware modifications or unsafe burning processes. But we Duemilanove owners still want to send an occasional keyboard event from time to time. I've written an Arduino library with a corresponding piece of software to go on your PC (Windows only for now guys, sorry) to evoke the events the Arduino is sending.

The Arduino part is pretty straight forward. It sends structured messages to the receiver on the PC, which are structured like this:
sk [command] [key_code]

A command can be either, press, release or tap (press and release), the key_code is something Microsoft provides us with here. The receiver takes the key_code and tells the oprating system what do with it according to the command received from the Arduino.

Which means you can do stuff like, hold Shift, tap 1, release Shift. Which will in return get you an ! on the PC.

The Arduino code for such a task will looks like this:

 #include <SoftKeyboard.h>  
   
 SoftKeyboard sk;  
   
 void setup() {  
  Serial.begin(9600); //Must init Serial in order for SoftKeyboard to work!  
 }  
   
 void loop() {  
  sk.press(0x10);  //hold Shift down  
  sk.tap(0x31);   //tap '1' (with shift makes it '!')  
  sk.release(0x10); //release Shift  
  delay(1000);  
 }  

The receiver was implemented with C#, using some un-managed code of course (other wise you can not get full advantage of Windows' keyboard APIs).

Notes:
You can't see the serial port traffic form the Arduino IDE and be connected to the SoftKeyboard receiver at the same time, so the receiver has a -v option, to let you see what the Arduino is sending.

Ok, that was enough blah-blah, you can find the code and the receiver .exe here: https://github.com/MeLight/soft-keyboard

Let me know if you have questions or suggestions (you can do to that in the repo too of course)

7 comments:

  1. could you provide c# code that u have written Thanks :)
    For a such a project

    ReplyDelete
  2. Hey could you make a 32bit version too? The one downloadable is only 64bit :(
    Already thanks alot man! You make my Duemilanove feel young again :p

    ReplyDelete
    Replies
    1. Hi man, thanks for using it. I'm afraid I don't have access to a 32 bit machine at the moment. But you can take the Program.cs file and compile it in Visual Studio Express, it will provide you with 32bit version of the .exe if you do it on a 32bit machine

      Delete
  3. Hi.

    Thank you for sharing this information. about Software only Arduino keyboard emulator this information was so useful to us.

    Here is sharing some Oracle Project Accounting information may be its helpful to you.

    Oracle Project Accounting Training

    ReplyDelete
  4. Hi.
    Than you for sharing this information it was good and this blog was giving good information.
    and Here is sharing some Salesforce Service Cloud information that may be helpful to you.

    Salesforce Service Cloud Training





    ReplyDelete