Switching Apps on Mac with AWT Robot only sometimes works

后端 未结 1 1932
星月不相逢
星月不相逢 2021-01-24 15:45

I\'m trying to use Robot in order to switch apps, and then enter some text. To do this (on my mac), I\'m pressing Meta, Tab, and then releasing Tab, Meta in this order:

1条回答
  •  不思量自难忘°
    2021-01-24 16:02

    Ah.. Seems that I need to specify a delay between the events. Updated:

                Robot robot = new Robot();
                robot.keyPress(KeyEvent.VK_META);
                robot.delay(300);
                robot.keyPress(KeyEvent.VK_TAB);
    
                robot.keyRelease(KeyEvent.VK_TAB);
                robot.keyRelease(KeyEvent.VK_META);
    

    0 讨论(0)
提交回复
热议问题