and .write do not work

I know that there is a lot of forum discussion regarding using a Photon as a Human Interface Device. I have read all of the previous threads regarding HID. We have a simple script which I will include below. The Keyboard.print() function works well, however, and Keyboard.write() do nothing at all. I have tried key codes i found on these forums, as well as the codes on . Even‘n’) does not work. Thanks for the help, here is the code:

void setup() {

void loop() {
    Keyboard.write(131); //Should press the left windows key, but does nothing
    Keyboard.print(""); //print works

It should be noted I am using the 0.6.0-rc.2 firmware on a Photon

Have you seen this?

That might explain why your code doesn’t work, which doesn’t mean the function doesn’t do what it’s supposed to do.

And for press() you might want to try a release() too - or just the click() which bundles both.
And as for your'n') what did you expect to happen, and what do the docs say should happen?

'n' equals 0x6E which in turn maps to KEY_F19 = 0x6E, // Keyboard F19

Did you check if KEY_F19 was pressed or did you expect to get a load of letters n typed?

1 Like

Did you make any progress on this? It looks like @ScruffR explained why write didn’t work.

It looks like click() should work however the Windows key isn’t called out in the keycode enum map. From this SO post it looks like it could be 5B or 5C which map to KEY_KP_3 and KEY_KP_4 respectively in the keycode enum map.

EDIT: Looks like it’s actually KEY_LEFTGUI and KEY_RIGHTGUI as @avtolstoy mentions below

EDIT 2: Added a PR to address this issue

‘Windows’ key is actually KEY_LEFTGUI or KEY_RIGHTGUI. It’s also Command key on OSX and Meta key on *nix.

1 Like

@MatthewJGilbert, I can positively confirm that and .write() both work okay.

@ScruffR has given excellent advice.

Perhaps refer to this ticket which showed my initial misunderstanding of what .press() is expecting:

1 Like