无法在 Java 中使用机器人按 Window+L

2022-01-21 00:00:00 windows-8 java awtrobot

我正在使用 Robot 类来模拟 Java 中的按键.但是我无法按窗口键+L,尽管我可以单独按它们.这是我的代码:

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:

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);
}

推荐答案

试试这个:

Runtime.getRuntime().exec("rundll32 user32.dll,LockWorkStation");

相关文章