8

我正在使用 Robot 类来模拟 Java 中的按键。但是我无法按窗口键+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);
}
4

3 回答 3

13

试试这个:

Runtime.getRuntime().exec("rundll32 user32.dll,LockWorkStation");
于 2012-11-02T10:52:43.030 回答
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);
于 2014-01-12T00:02:14.947 回答
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);
}
于 2012-11-02T10:29:33.150 回答