我正在使用Robot类来模拟Java中的按键。但我无法按下Window键+ L,虽然我可以单独按下它们。这是我的代码:
private void pressKey()
{
Robot r=new Robot();
robot.keyPress(KeyEvent.VK_WINDOWS);
robot.keyPress(KeyEvent.VK_L);
robot.keyRelease(KeyEvent.VK_WINDOWS);
robot.keyRelease(KeyEvent.VK_L);
}
答案 0 :(得分:12)
请改为尝试:
Runtime.getRuntime().exec("rundll32 user32.dll,LockWorkStation");
答案 1 :(得分:0)
尝试:
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);
}
答案 2 :(得分:0)
试试这个:
robot.keyPress(KeyEvent.VK_WINDOWS);
robot.delay(100);
robot.keyPress(KeyEvent.VK_L);
robot.delay(200);
robot.keyRelease(KeyEvent.VK_L);
robot.delay(100);
robot.keyRelease(KeyEvent.VK_WINDOWS);