[英]Java awt.Robot: CTRL+ALT+DEL does not bring up desired screen
I just recently found out about the awt.Robot Library and I'm quite excited to get to use it. 我刚刚发现了awt.Robot库,我很高兴能够使用它。 I thought I'd play a little prank on my friend and have the robot press control,alt,delete press the lock the computer button but I can't get the program to bring up the control alt delete screen. 我以为我会对我的朋友玩一个小恶作剧,并有机器人按下控制,alt,删除按下锁定电脑按钮,但我无法让程序调出控制alt删除屏幕。
Here's my code: 这是我的代码:
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);
}
}
This cannot be done in Windows XP 1 (+ patches?) onward with simulated key events. 在模拟键事件的Windows XP 1 (+补丁?)中无法完成此操作。
From a comment here on an old article showing how this used to be able to be simulated: 从这里评论上显示如何这个曾经能够模拟一个旧文章:
For secure reasons on Vista we can not broadcast hotkey message to simulate CTRL ALT DEL. 出于安全原因,我们无法播放热键消息以模拟CTRL ALT DEL。 To do this on VISTA you need to use a special library "SASLIB" not provided by default... 要在VISTA上执行此操作,您需要使用默认情况下未提供的特殊库“SASLIB”...
Anyway, if you use the Win32 (or whatever OS) API directly, you probably have access to the appropriate API to perform a task. 无论如何,如果直接使用Win32(或任何操作系统)API,您可能有权访问相应的API来执行任务。 For instance, see LockWorkStation : 例如,请参阅LockWorkStation :
This function has the same result as pressing Ctrl+Alt+Del and clicking Lock Workstation. 此功能与按Ctrl + Alt + Del并单击“锁定工作站”的结果相同。
See Is there a Java library to access the native Windows API? 请参阅是否有Java库来访问本机Windows API? for leads on how the native (Windows) API can be accessed. 了解如何访问本机(Windows)API。
1 From the description of the operation I'm assuming the target is Windows. 1从操作说明我假设目标是Windows。
I looked up how to access Ctrl + Alt + Del through the command line and unfortunately it is not possible. 我查找了如何通过命令行访问Ctrl + Alt + Del ,不幸的是,这是不可能的。
However, it is possible to lock the computer through the command line using this code: 但是,可以使用以下代码通过命令行锁定计算机:
try {
Runtime.getRuntime().exec("rundll32 user32.dll,LockWorkStation");
} catch (IOException ex) {
Logger.getLogger(TimeFrame.class.getName()).log(Level.SEVERE, null, ex);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.