Simulate the pressing of the "Command" key on a Mac
n the Robot
class, the name for Command(⌘) is KeyEvent.VK_META
. Your code should look like this:
Robot r = new Robot();
r.keyPress(KeyEvent.VK_META);
r.keyPress(KeyEvent.VK_L);
r.keyRelease(KeyEvent.VK_META);
r.keyRelease(KeyEvent.VK_L);
This presses the Command key, presses the L key, then releases them both. I have tested this, and it works as it should.
NOTE: Using Robot
throws AWTException
, so it requires you to either surround with try-catch block, or throw AWTException
in your method header