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?
2 Answers 2
They 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.
The modifier 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).
Unluckily the 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_LEFT_GUI
and 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_LEFT_GUI);
orkeyboard.press(KEY_RIGHT_GUI);
, or use thekeyboard.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.
Good luck
Explore related questions
See similar questions with these tags.
Control Key + number Key 1
... Keyboard.press(KEY_LEFT_GUI); Keyboard.press('which value I need to enter for key 1?'); Keyboard.releaseAll();