简体   繁体   中英

How to disable the Start button in Java Swing application?

I am making a Desktop application using Java-Swing which is used to lock the desktop home screen.

I have used JFrame with Maximum size (as per Desktop resolution ie 1366x768). I have already disable alt-f4 and alt-tab key pairs. But how to disable Start button in keyboard?

The following code works in an example for me.

with 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;
    }
}

with 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();
    }
}

FYI:

/**
 * 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM