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.
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.
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.
posted 7 years ago
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.
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 ...