Home:ALL Converter>Detect the Windows key modifier

Detect the Windows key modifier

Ask Time:2014-11-19T17:45:21         Author:SeniorJD

Json Formatter

How can I detect the Windows key modifier for KeyEvent? I have add the code:

textField.addKeyListener(new KeyAdapter() {
    public void keyReleased(KeyEvent e) {
        if ((e.getKeyCode() & KeyEvent.VK_ESCAPE) == KeyEvent.VK_ESCAPE) {
            textField.setText("");
        }
    }
});

But the problem is, when I use the Windows zoom and try to exit from it using Win + Escape, if focus is in TextField, its content clears. I've tried filter by e.getModifiersEx(), but it returns 0. The only way I've found is to detect whether Windows pressed or not, is to create boolean field and change it's value when Windows pressed/released.

So, is there any way to get the Windows key pressure state from KeyEvent for ESCAPE released event?

Author:SeniorJD,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/27013566/detect-the-windows-key-modifier
yy