使用Java Robot的Alt + Tab [英] Alt+Tab using Java Robot
问题描述
我正在尝试使用Java Robot弹出 alt + tab 菜单.当我调用alt_tab()方法时,我想调出 alt + tab 菜单并保持菜单不变.我知道可以使用 alt + ctrl + tab 来实现.
I am trying to bring up the alt+tab menu with a Java Robot. When I call the alt_tab() method, I want to bring up the alt+tab menu and keep the menu up. I know this can be achieved using alt+ctrl+tab.
到目前为止,我已经尝试了下面的代码,并且只尝试了 alt + tab ,而没有控制键.我不确定为什么不显示菜单.它所做的只是模拟按Alt键.
So far I have tried the code below, and also just alt+tab without the control key. I am not sure why it's not bringing up the menu. All it does is emulate pressing the alt key.
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);
}
我正在使用Windows 8 Pro和JDK7.不胜感激!
I am using Windows 8 Pro and JDK 7. Any help is appreciated!
推荐答案
我能够找到一种解决方法.我按照此上的说明进行操作网站创建指向 ALT + TAB 菜单的快捷方式,然后使用
I was able to find a workaround. I followed the instructions on this site to create a shortcut to the ALT+TAB menu, and use
Runtime.getRuntime().exec("cmd \c start " + <path\to\shortcut\>);
在没有任何特殊UIAccess特权的情况下启动 ALT + TAB 菜单.感谢大家的回应.
to launch the ALT+TAB menu without any special UIAccess privileges. Thanks to everyone for their responses.
这篇关于使用Java Robot的Alt + Tab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!