Can a device pretend to be a USB keyboard? What I'm looking for:

Is there a way to make the device claim to be a keyboard/HID when plugged into a USB port and "type in" the contents of the clipboard? More accurately; What would it take to make it happen?

Motivating use case:

I have a password keeper program on my phone but it's annoying to have to read the password off the device and try to type it into another computer.

Background:

I have an Android device that was built before MTP was supported for transferring file but, with recent upgrades, now supports it. Based on this, the USB class that it claims to be can't be hardware defined and must be defined in software.

IIRC, this project has Android devices (with what I think is a stock kernel) talking as some USB class that was definitively not built in. This indicate to me that you might be able to control what USB classes it support without kernel work but I don't know for sure.

As for the Host side (i.e. the PC), I've never seen a PC, Mac or Linux box need special drives for keyboards, even for some rather esoteric devices that claim to be keyboards (bar-code scanners, credit card and smart card readers, etc.) so the generic drivers should be good enough for what I'm wanting.

All that argues that what I'm looking for can be done from a hardware point of view, but says very little about what software support exists and nothing about if there is an app for it.
Yes. This is definitely possible, requiring no modifications or drivers on the PC. As the OP mentions, the USB identification on the phone end is ultimately done in software (in this file https://github.com/android/kernel_msm/blob/android-msm-2.6.35/drivers/usb/gadget/composite.c), and it could be modified to identify itself as a standard USB keyboard. 

This change would require a couple of things.


A modified kernel with a patched USB driver
An Android app that could talk to some interface exposed by the modified USB driver.


There was a paper published a couple of years ago (titled Exploiting smart-phone USB connectivity for fun and profit) that described using a phone to brute-force desktop login screens. The method they used involved making the phone appear as a USB keyboard.