删除可以使用Alt-F4和Alt-TAB在Java GUI中
问题描述:
可能重复的可能性:
Java Full Screen Program (Swing) -Tab/ALT F4删除可以使用Alt-F4和Alt-TAB在Java GUI中
我有一个全屏幕帧运行,我想效仿一个Kiosk环境。要做到这一点,我需要“捕捉”所有Alt键的出现 - F4和Alt键 - 标签在任何时候按下键盘上。这甚至有可能吗?我的伪代码:
public void keyPressed(KeyEvent e) {
//get the keystrokes
//stop the closing or switching of the window/application
}
我不知道的keyPressed和它的联营公司(的keyReleased和的keyTyped)都去,因为从我读过,他们只能处理一个键/字符的正确途径。
答
要停止的Alt-F4:
yourframe.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
要停止使用Alt-Tab,就可以使一些更有侵略性。
public class AltTabStopper implements Runnable
{
private boolean working = true;
private JFrame frame;
public AltTabStopper(JFrame frame)
{
this.frame = frame;
}
public void stop()
{
working = false;
}
public static AltTabStopper create(JFrame frame)
{
AltTabStopper stopper = new AltTabStopper(frame);
new Thread(stopper, "Alt-Tab Stopper").start();
return stopper;
}
public void run()
{
try
{
Robot robot = new Robot();
while (working)
{
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_TAB);
frame.requestFocus();
try { Thread.sleep(10); } catch(Exception) {}
}
} catch (Exception e) { e.printStackTrace(); System.exit(-1); }
}
}
+0
奇妙!谢谢,这正是我所需要的。 – n0pe 2011-05-25 17:01:04
+0
不客气。 – 2011-05-25 17:43:57
是否可以禁用某些软件(这是常见的)Windows键,那么就应该禁用ALT + F4 /选项卡的功能 – dantuch 2011-05-25 16:33:52
重复的发现为从谷歌搜索上的Java的第一个结果没有问题防止alt f4'。在提问之前尝试搜索,因为答案可能已经在那里。 – Codemwnci 2011-05-25 16:35:49
上面引用的帖子没有回答我的问题,似乎只是真正触及使应用程序全屏。所以我问了这个问题。 – n0pe 2011-05-25 16:41:21