Well, I couldn’t check it correctly, as on my system, Windows + Left or Right were intercepted and processed by Windows even for unordered frames, however, adding another case for an unused combination of Windows + A proved that the following code works if the host system doesn't use a key shortcut:
(Update: since this is apparently the key press that Windows consumes, you can select the Windows key + Left or Right )
final JFrame frm = new JFrame("Test"); final JTextField field = new JTextField(); frm.add(field, BorderLayout.NORTH); frm.getToolkit().addAWTEventListener(new AWTEventListener() { boolean winDown; public void eventDispatched(AWTEvent event) { KeyEvent ev=(KeyEvent)event; final boolean pressed = ev.getID()==KeyEvent.KEY_PRESSED; if(ev.getKeyCode()==KeyEvent.VK_WINDOWS) winDown=pressed; else if(winDown) switch(ev.getKeyCode()) { case KeyEvent.VK_LEFT: System.out.println("windows + LEFT "+(pressed?"pressed":"released")); break; case KeyEvent.VK_RIGHT: System.out.println("windows + RIGHT "+(pressed?"pressed":"released")); break; case KeyEvent.VK_A: System.out.println("windows + A "+(pressed?"pressed":"released")); break; } } }, KeyEvent.KEY_EVENT_MASK); frm.setUndecorated(true); frm.setSize(500, 550); frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frm.setVisible(true);
It seems that the normal key listener on the component does not work, because the component loses focus when Windows is pressed.
source share