File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Android and the fly likes Use android device as USB keyboard Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Use android device as USB keyboard" Watch "Use android device as USB keyboard" New topic

Use android device as USB keyboard

T Dahl
Ranch Hand

Joined: Oct 07, 2010
Posts: 35
I'd like to create an app that is able to send (simulated) keystrokes to a PC over a USB connection.

Before I dive into the specs for USB and Human Interface Device (HID) I'd like to know if someone else has already created useful classes or other code to get me started.

To clarify:
The PC is to be the USB host, the android device being the slave.
The app will create the character to transmit to the PC as a keystroke (e.g. an 'A').
I'd like to invoke a method that will implement the transmission of the keystroke (given as a parameter to the method).
If such a method has already been written, let me know. Otherwise please point me to other useful code that may help me implement it.
thomas brian

Joined: Apr 19, 2012
Posts: 16
android-pcbcr - Project Hosting on Google Code. The idea of it is that the phone scans a barcode and sends the data over the network to the PC where the keystrokes are then simulated. So if sending the data over a network to the PC is acceptable instead of plugging in a USB cable, then it wouldn't take too much effort to adapt the code to send the keystrokes from the phone instead of the barcode data. It wouldn't require root access on the phone. What do you think? Your USB idea is more flexible (don't need to have network access), but I wouldn't know how to do that at the moment.
T Dahl
Ranch Hand

Joined: Oct 07, 2010
Posts: 35
Thank you for the reply thomas!

Yes, there are a few reasons why I am thinking of using USB:
- It is very easy to use for a simple proof of concept demo (assuming I actually get the code to work on Android)
- I want to avoid installing anything on the PC if I can.
- The delay from activating the Android device to character accepted at the PC should be short and predictable. Probably not a big issue with a modern LAN but no issue at all with USB.
If successfully implemented on USB it should be easily portable to Bluetooth (which also uses HID).

What I have figured out so far:

There is USB support in Android. The class UsbAccessory represents the other device (e.g. a PC) as a host. However to do actual communication with the other device one needs to use UsbManager which according to the documentation supports host mode only. It is possible that my luck ran out there.

Android itself does not seem to have support for HID (Human Interface Device). I have found the official standard. It is non-trivial.
Bap Hensley

Joined: Jul 03, 2012
Posts: 1
I am not an android developer, but I have been searching for this capability for over year, and want to encourage you. I provide deskside support in an environment where adding software is discouraged and difficult, and the workstations do not have bluetooth stacks, and network access is not available for personal devices. I have Parkinson's and the shaking is making it difficult to keyboard and mouse. I'd like to be able to carry my tablet to a workstation, "jack in", and use Nuance's FlexT9 (or similar) for input ... therefore, USB HID.

I doubt this will help, but here are a few leads I found a while back that seemed related ...

teensy arduino
USB kbd driver in linux (Android) - f_hid
stavrou wang how-to android hid [bluetooth]

Good luck!

Nick Johnson

Joined: Jun 21, 2012
Posts: 16
Hey, nice concept.. Surely, a concept kipping future in mind........ Thank you for the post.......
I agree. Here's the link:
subject: Use android device as USB keyboard
It's not a secret anymore!