我正在使用 Java-Swing 制作一个桌面应用程序,用于锁定桌面主屏幕。
我使用了最大尺寸的JFrame
(根据桌面分辨率,即1366x768)。我已经禁用 alt-f4 和 alt-tab key 对。
但如何禁用键盘上的“开始”按钮呢?
最佳答案
以下代码适用于我的示例。
使用 KeyEventDispatcher:
public class WindowsKey extends JPanel implements KeyEventDispatcher {
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getID() == KeyEvent.KEY_TYPED) {
int code = e.getKeyChar();
if (KeyEvent.VK_WINDOWS == code) {
return true;
}
}
return false;
}
}
使用 KeyListener:
// Invoked when a key has been pressed.
public void keyPressed(KeyEvent e) {
// Returns the integer code for the key on the keyboard and if
// keyCode is equal to VK_WINDOWS)...
if (e.getKeyCode() == KeyEvent.VK_WINDOWS) {
// ...call the doIT method.
doIT();
}
}
仅供引用:
/**
* Constant for the Microsoft Windows "Windows" key.
* It is used for both the left and right version of the key.
* @see #getKeyLocation()
* @since 1.5
*/
public static final int VK_WINDOWS = 0x020C;
关于java - 如何禁用 Java Swing 应用程序中的“开始”按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28876867/