gpt4 book ai didi

Java awt.Robot : CTRL+ALT+DEL does not bring up desired screen

转载 作者:搜寻专家 更新时间:2023-11-01 02:27:02 26 4
gpt4 key购买 nike

我最近才发现 awt.Robot 库,我很高兴能够使用它。我想我可以对我的 friend 开个恶作剧,让机器人按下 control、alt、delete 按下锁定计算机按钮,但我无法让程序调出控制 alt 删除屏幕。

这是我的代码:

import java.awt.*;
import java.awt.event.KeyEvent;
public class Bot {
public static void main(String[] args)
{
try {
Robot bot = new Robot();
bot.delay(4000);
bot.keyPress(KeyEvent.VK_CONTROL);
bot.delay(100);
bot.keyPress(KeyEvent.VK_ALT);
bot.delay(100);
bot.keyPress(KeyEvent.VK_DELETE);
bot.delay(500);
bot.keyRelease(KeyEvent.VK_CONTROL);
bot.keyRelease(KeyEvent.VK_ALT);
bot.keyRelease(KeyEvent.VK_DELETE);
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

public static void pressEnter(Robot bot)
{
bot.keyPress(KeyEvent.VK_ENTER);
bot.delay(40);
bot.keyRelease(KeyEvent.VK_ENTER);
}
}

最佳答案

这不能在 Windows XP1(+ 补丁?)中使用模拟按键事件来完成。

来自comment here在一篇显示如何使用进行模拟的旧文章上:

For secure reasons on Vista we can not broadcast hotkey message to simulate CTRL ALT DEL. To do this on VISTA you need to use a special library "SASLIB" not provided by default...

无论如何,如果您直接使用 Win32(或任何操作系统)API,您可能可以访问适当的 API 来执行任务。例如,参见 LockWorkStation :

This function has the same result as pressing Ctrl+Alt+Del and clicking Lock Workstation.

参见 Is there a Java library to access the native Windows API?有关如何访问 native (Windows) API 的线索。


1 根据操作的描述,我假设目标是 Windows。

关于Java awt.Robot : CTRL+ALT+DEL does not bring up desired screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19782781/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com