删除在Java GUI中使用Alt-F4和Alt-TAB的可能性 [英] Remove the possibility of using Alt-F4 and Alt-TAB in Java GUI
本文介绍了删除在Java GUI中使用Alt-F4和Alt-TAB的可能性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个全屏框架正在运行,我希望模仿Kiosk环境。要做到这一点,我需要捕获所有出现的 Alt - F4 和 Alt - Tab 按下键盘在任何时候。这有可能吗?我的伪代码:
I've got a full screen frame running and I wish to emulate a Kiosk environment. To do this, I need to "catch" all occurrences of Alt-F4 and Alt-Tab pressed on the keyboard at all times. Is this even possible? My pseudocode:
public void keyPressed(KeyEvent e) {
//get the keystrokes
//stop the closing or switching of the window/application
}
我不确定是否keyPressed和它的关联(keyReleased和keyTyped)是正确的方法因为从我读过的,它们只处理单个键/字符。
I'm not sure if keyPressed and it's associates (keyReleased and keyTyped) are the right way to go because from what I've read, they only handle single keys/chars.
推荐答案
停止Alt-F4:
yourframe.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
要停止Alt-Tab,你可以做一些更积极的事情。
To stop Alt-Tab, you can make something more aggressive.
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); }
}
}
这篇关于删除在Java GUI中使用Alt-F4和Alt-TAB的可能性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文