Is it possible to allow an arduino Leonardo to simulate pressing the windows key using the
keyboard.press(......); command? If so, what is the required value?
Keyboard.press() command accept modifiers per the documentation . You may need to do multiple
press() commands before releasing.
For example, if you want to launch Explorer you could use:
Keyboard.press(KEY_LEFT_GUI); Keyboard.press('e'); Keyboard.releaseAll();
This is equivalent to shortcut keys
windows + e
GUI is what stands in for the "command key" which is the Windows Logo on PC or Clover (⌘) on Mac.
I am not having any restriction on the higher value on my board (Pro Micro) as indicated by @frarugi87
Looking at the list of the HID keyboard codes (page 53), the keys you are looking for have a code of E3 (Keyboard Left GUI) or E7 (Keyboard Right GUI).
Keyboard::press function (you can see it here) does not accept a so high value, since you can only input numbers between 0 and 255 and, in order to send a raw value, you have to send its value plus 136 (which leads to values 363 and 367).
However, looking at the header file, there are two predefined keys called
KEY_RIGHT_GUI. Maybe these modifier keys behave in exactly the same way.
So my suggestion is to
- try using one of those values (i.e.
keyboard.press(KEY_RIGHT_GUI);, or use the
keyboard.write(KEY_LEFT_GUI);to simulate a press on the key instead of you keeping it pressed).
- If this does not work, create your own library copying the keyboard.cpp and keyboard.h files, calling the class differently and adding the possibility to send the E3 and/or the E7 keys. In this case, you will just need to modify the press function.