Is it possible to allow an Arduino Leonardo to simulate pressing the Windows key using the
If so, what is the required value?
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.Sign up to join this community
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 File Explorer you could use:
Keyboard.press(KEY_LEFT_GUI); Keyboard.press('e'); Keyboard.releaseAll();
This is equivalent to shortcut keys Win + E.
GUI is what stands in for the "command key" which is the Windows Logo on a PC or clover (⌘) on a Mac.
I don't have 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
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).