Question: Getting a Raspberry Pi to output data by emulating a keyboard

warren is asking a question about raspberry-pi
Follow this topic

by warren | April 29, 2017 20:28 | #14151

What I want to do

Folks are using the Raspberry Pi, a cheap stripped-down computer available for as little as $5, to connect to sensors, record weather data, and even run a DIY spectrometer. But it's hard to get data off of them easily, and hard to set them up.

But there seem to be ways to get them to "act like a keyboard" and, when connected to a computer by USB, to simply "virtually type" out data. This would work on Windows, Linux, and Mac, and be really simple -- no mucking around with Bluetooth, WiFi, SD cards, etc.

I've found a lot of resources on this:

Two approaches to getting a Pi to "act like a keyboard" using the "USB Gadget" system and the "HID" (human interface device) spec:

There's guidance on how to actually use and test it here:

And a bit more on the actual codes and how to get it to "type" any text here:

Ideal outcome

What I'd really like is an image of an SD card with all of this set up already -- or a script that'll run on an image very straightforwardly. That way this could be set up with minimal difficulty by folks who are trying to do sensing with Raspberry Pis!

Anyone want to take a crack at it?


Made some progress; i've gotten the "ethernet" usb gadget to work as shown here (and found this much simpler instruction set with lots of helpful comments)

I found there's an actual utility for piping text to the "virtual keyboard" from the commandline:

Also found this Android-based implementation with a utility to actually output the correct codes to the device once it's running: (although the above does this too)


To clarify, this problem is concerned just with sending data over the USB? Collecting data in the first place is separate?

Would you want the pi to continuously transmit (typing into a connected text file?) Or to collect data prior and then sync to a computer afterwards?

Is this a question? Click here to post it to the Questions page.

Reply to this comment...

Are you storing data in RAM on the Pi? In a RAM drive? Do these data persist after the Pi is powered down? Is this Pi always connected to a computer for this data acquisition and transfer?

Is this a question? Click here to post it to the Questions page.

Reply to this comment...

Hi folks! I'm starting with the general case here, that a pi could act as a keyboard (an HID interface), for any of the above cases. I think we could have a way to cache data either in memory or on the disk, and "play it all back" -- or a continuous mode where it types data while it captures it. Imagine a pi camera that's used in a spectrometer; you could have it type the data just after it takes a picture. Or a weather station could "spit out" a week's worth of data it had stored.

At this point I'm most interested in the general ability to virtually type, upon which we could build a range of functions. Modularity!


Reply to this comment...

I think this should be relatively easy if you are using the Pi Zero. See

But for all other Pi devices I think it is not possible without hardware mods since they do not have support USB OTG. See

Is this a question? Click here to post it to the Questions page.

That said, reading makes it sound like maybe all Pis support OTG

Reply to this comment...

Log in to comment