Using Java to set the focus to a non Java application in Windows

前端 未结 5 647
一整个雨季
一整个雨季 2020-12-06 09:56

I would like to write an application who creates input for a non-Java application in Windows. With the Robot class it\'s easy to generate the input, but I need to set the fo

5条回答
  •  余生分开走
    2020-12-06 10:30

    Configure a delay otherwise it won't work:

    Robot r = new Robot();
    r.keyPress(KeyEvent.VK_ALT);
    r.keyPress(KeyEvent.VK_TAB);
    r.delay(10); //set the delay
    r.keyRelease(KeyEvent.VK_ALT);
    r.keyRelease(KeyEvent.VK_TAB);
    

提交回复
热议问题