Cannot press Window+L using robot in Java

前端 未结 3 464
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 17:21

I am using the Robot class to simulate key press in Java. But i am unable to press Window key+L although i am able to press them individually. Here is my code:



        
3条回答
  •  执念已碎
    2020-12-11 17:40

    Try:

    private void pressKey(){
       Robot r=new Robot();
       robot.keyPress(KeyEvent.VK_WINDOWS);
       robot.keyPress(KeyEvent.VK_L);
       robot.keyRelease(KeyEvent.VK_L);
       robot.keyRelease(KeyEvent.VK_WINDOWS);
    }
    

提交回复
热议问题