Using Java to send key combinations

前端 未结 4 1570
孤独总比滥情好
孤独总比滥情好 2020-12-09 12:02

As per this previous link (How to send keyboard outputs) Java can simulate a key being pressed using the Robot class. However, how could a combination of key presses be simu

4条回答
  •  时光取名叫无心
    2020-12-09 12:37

    This is an example

    Robot r = new Robot();
    Thread.sleep(1000);
    
    r.keyPress(KeyEvent.VK_ALT);
    r.keyPress(KeyEvent.VK_NUMPAD1);
    r.keyPress(KeyEvent.VK_NUMPAD2);
    r.keyPress(KeyEvent.VK_NUMPAD3);            
    r.keyRelease(KeyEvent.VK_ALT);
    

    Don't forget to release some special keys, it will make some crazy things on your machine

提交回复
热议问题