Having trouble finding documentation for emulating a keyboard

I am trying to have my photon press key buttons through usb (USB HID) and I read that it is possible, however, I cannot find documentation or example code on how to do it. Maybe someone here can help me?

1 Like

It’s not officially implemented in the current firmware but will be in the upcoming 0.6.0.

If you feel comfortable with building the firmware with a local toolchain, you can already use these features.


@scruffr, out of interest, is there pre-release documentation for the USB HID interface?

Not that I know of, but I think I’ve seen something on GitHub either as an issue/pull request discussion.

I guess the feature branch back in 2014 and the related threads on here are a bit outdated.

@ScruffR, I understand that issue #528, “Photon can function as a HID device”, https://github.com/spark/firmware/issues/528, has been closed and due for release 0.6.0 as you have said.

Was really just wondering how HID USB was going to be implemented in relation to key make and break, control keys, function keys and the like.

In lieu of documentation, I took the leap and downloaded the firmware source code from Git and found these files:


which declared the USBKeyboard class and defines like:


So this is good news.

The scary bit is that the source files were dated 31 March 2014…

So, @Nimonster, it (hopefully) looks like just a little bit more patience is required!

These files from 2014 did already work back then and didn’t need any alterations since they mainly deal with the standard/abstracted side of things.
The tricky part - which has changed since then - is the way how the USB HID descriptors were put together and how the respective HID objects would be exposed/made available for application code.

So no worries if the Wiring files don’t change, as this end of the chain has to stay pretty much unaltered to keep Arduino compatibility.

Ok, thanks for the info

Is there any update on documentation so far?

There is no update on the feature for the current release either, so no point updating the docs for a non-present feature :wink:

So does that work or not?
https://github.com/spark/firmware/issues/528 is closed, Pull request is merged https://github.com/spark/firmware/pull/902 however using in Web IDE brings "‘Keyboard’ was not declared in this scope"
Only available when compiling manually from develop branch?

Is Keyboard.begin() included in current 0.6.0rc2? Still produces error when included in WEB IDE

My bad, haven’t properly switched firmware version. Still currently 0.6.0 fails in WEBIDE with “Server failed to process request”, will try later

Yes, still no “Keyboard” in 0.6.0rc2 :frowning:

 'Keyboard' was not declared in this scope

But I thought it was merged in develop quite long time ago

That is very confusing. Git tag 0.6.0rc2 even has unit tests for Keyboard and Mouse, but they are not avaiable in Web IDE

There is, the only thing is that previously installed Particle drivers do interfere with the system HID drivers.

There is an elaborate info how to uninstall the old ones correctly with the respective pull request, but I also got it working by removing all Particle COM devices (including the drivers on the harddrive).
To do that you need DEVMGR_DISPLAY_NONPRESENT_DEVICES=1 in your environment variables and Show hidden devices in DevMgr

Is 0.6.0-rc.2 related to 0.6.0-rc.2 tag in GIT? I’m trying to use ‘Keyboard.begin()’ and ‘Mouse.begin()’ that should already exist there, but Web IDE fails to use them. Git even has unit tests for them on that tag, so I’d expect them working, but they are not

I moved this here since it didn’t actually fit the other thread
See my post above

Why does it throws an error in Web IDE if it is there? See screenshot

I don’t know.

This builds fine for me

void setup() {

void loop() {

Have you actually selected 0.6.0-rc.2 as target?

Keyboard is working fine for me too on 0.6.0-rc.2