[英]Issue Using Java AWT Robot class
I am using the robot class and trying to stroke the keys ctrl+alt+del
我正在使用机械手类并尝试敲击
ctrl+alt+del
键
Below is the code 下面是代码
public class RobotClassDemo{
public static void main(String[] args) {
try {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
System.out.println("ctrl pressed");
robot.keyPress(KeyEvent.VK_ALT);
System.out.println("alt pressed");
robot.keyPress(KeyEvent.VK_DELETE);
System.out.println("delete pressed");
} catch (AWTException e) {
e.printStackTrace();
}
}
}
But it is not giving me any option like I am asuming here that it will move to screen which will contain lock , shut down , change password etc.(as in window 7 happens when we press ctrl+alt+del).I am running this program on windows 7.I sthere any limitations or access previliges? 但是它没有给我任何选择,就像我在这里假设的那样,它将移动到包含锁定,关闭,更改密码等的屏幕(如在窗口7中,当我们按ctrl + alt + del时发生)。 Windows 7上的该程序。我是否有任何限制或访问权限? Or what is the problem?
还是什么问题?
Edit: Even My this code is working great 编辑:即使我的这段代码也很好用
public void alt_tab() {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(100);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_ALT);
}
But dont know what is the problem with the first one 但是不知道第一个是什么问题
I wouldn't be completely surprised if this were forbidden by the OS or environment; 如果操作系统或环境禁止这样做,我不会感到完全惊讶。 however, have you tried adding
robot.keyRelease
events? 但是,您是否尝试添加
robot.keyRelease
事件? At the moment it's as though you're holding the keys down forever. 目前,好像您一直按住这些键一样。 This may be insufficient to fire the appropriate key up/down/press events that the OS uses to recognise this key combination.
这可能不足以触发操作系统用来识别此组合键的适当的向上/向下/按下事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.