title: How to handle Windows key press with SWT AWT, minimize window and go back to desktop
body: <p>For my firsts steps with SWT (and more generally with Java), I try to make a simple app with few basics components. It's a simple window which maximise with NO_TRIM.</p>
  
  <p>Now I want to write an EventHandler on the Windows system key press to hide this window and go back to desktop. After realizing that SWT.COMMAND works only with MacOS, I've replaced :</p>
  
  <pre><code>import org.eclipse.swt.events.KeyAdapter
  import org.eclipse.swt.events.KeyAdapter
  </code></pre>
  
  <p>with</p>
  
  <pre><code>import java.awt.event.KeyAdapter
  import java.awt.event.KeyEvent
  </code></pre>
  
  <p>But I still get this error : </p>
  
  <pre><code>The method addKeyListener(KeyListener) in the type Control 
      is not applicable for the arguments (new KeyAdapter(){})
  </code></pre>
  
  <p>I can't figure out what's happening. Here's my code :</p>
  
  <pre><code>import org.eclipse.swt.SWT;
  import org.eclipse.swt.graphics.Image;
  import org.eclipse.swt.graphics.Rectangle;
  import org.eclipse.swt.widgets.Display;
  import org.eclipse.swt.widgets.Event;
  import org.eclipse.swt.widgets.Listener;
  import org.eclipse.swt.widgets.Shell;
  
  import java.awt.event.KeyAdapter;
  import java.awt.event.KeyEvent;
  
  public class MyApp {
  
      private Shell shell;
      private Display display;
  
      /**
       * Launch the application.
       * @param args
       */
      public static void main(String[] args) {
          try {
              MyApp window = new MyApp();
              window.init();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      /**
       * Open the window.
       */
      private void init() {
          Display display = Display.getDefault();
          createContents();
          shell.open();
          while (!shell.isDisposed()) {
              if (!display.readAndDispatch()) {
                  display.sleep();
              }
          }
          display.dispose();
      }
  
      /**
       * Create contents of the window.
       */
      private void createContents() {
          shell = new Shell(display, SWT.NO_TRIM);
          shell.setText("MyApp");
          shell.setMaximized(true);
  
          final Image tmp_img_background = new Image(display, "img/background.png");
          shell.setBackgroundImage(tmp_img_background);
  
          shell.addKeyListener(new KeyAdapter() {
              //@Override
              public void keyPressed(KeyEvent e) {
                  if(e.getKeyCode() == KeyEvent.VK_WINDOWS) {
                      shell.setMinimized(true);
                  }
              }
          });
  
          shell.addListener(SWT.Resize, new Listener() {
              //@Override
              public void handleEvent(Event event) {
                  Rectangle clientArea = shell.getClientArea();
                  final Image img_background = new Image(display, tmp_img_background.getImageData().scaledTo(clientArea.width, clientArea.height));
                  shell.setBackgroundImage(img_background);
                  tmp_img_background.dispose();
              }
          });
      }
  }
  </code></pre>
  
  <p>Any help would be appreciated, thanks.</p>
  
  <h1><strong>EDIT</strong></h1>
  
  <p>I finally found a solution to do what's was expected. Instead of SWT I now use AWT/Swing.</p>
  
  <p>Here's the code I use now, it does the same thing except this time the "Windows key" bring you back to the desktop.</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.EventQueue;
  import java.awt.Image;
  import java.awt.event.KeyAdapter;
  import java.awt.event.KeyEvent;
  import javax.swing.ImageIcon;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  
  public class MyApp {
  
  private JFrame frame;
  private JPanel panel;
  private JLabel label;
  private ImageIcon imageIcon;
  
      /**
       * Launch the application.
       */
      public static void main(String[] args) {
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                  try
                  {
                      MyApp window = new MyApp();
                      window.frame.setVisible(true);
                  }
                  catch (Exception e)
                  {
                      e.printStackTrace();
                  }
              }
          });
      }
  
      /**
       * Create the application.
       */
      public MyApp() {
          initialize();
      }
  
      /**
       * Initialize the contents of the frame.
       */
      private void initialize() {
          frame = new JFrame("MyApp");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
          frame.setUndecorated(true);
          frame.getContentPane().setBackground(Color.BLACK);
          frame.setVisible(true);
  
          Dimension frameArea = frame.getSize();
          int w = frameArea.width;
          int h = frameArea.height;
  
          try
          {
              panel = new JPanel();
              imageIcon = new ImageIcon(
                  new ImageIcon(panel.getClass().getResource("/background.png"))
                  .getImage()
                  .getScaledInstance(w, h, Image.SCALE_DEFAULT)
              );
              label = new JLabel();
              label.setIcon(imageIcon);
              frame.setContentPane(label);
          }
          catch (Exception e)
          {
              System.out.println("File not found !");
          }
  
          frame.addKeyListener(new KeyAdapter() {
              //@Override
              public void keyPressed(KeyEvent e) {
                  if(e.getKeyCode() == KeyEvent.VK_WINDOWS) {
                      frame.setState(JFrame.ICONIFIED);
                  }
              }
          });
      }
  }
  </code></pre>