title: Java SyntheticEvent on KeyListener
body: <p>I am implementing some dialog windows that extend JDialog and need to implement some keyboard shortcuts, e.g.: </p>
  
  <pre><code>class MyDialog extends JDialog implements KeyListener
  {
      /** Constructor
       * 
       */
      public MyDialog() {
  
          super();
  
          // add keyboard shortcuts:
          addKeyListener(this);
          setFocusable(true);
      }
  
      // ---------------------------------------------------------
      //                 Keyboard shortcuts
      // ---------------------------------------------------------
      public void keyReleased(KeyEvent e) {}
      public void keyTyped(KeyEvent e) {}
      public void keyPressed(KeyEvent e)
      {
          System.out.println(e);
          if ((e.getKeyCode() == KeyEvent.VK_W) &amp;&amp; ((e.getModifiers() &amp; Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0)) {
              dispose();
          }
      }
  }
  </code></pre>
  
  <p>I then have a couple different types of dialog that extend MyDialog. When the keyboard shortcut is triggered, I get the following output on the console:</p>
  
  <pre><code>java.awt.event.KeyEvent[KEY_PRESSED,keyCode=157,keyText=?,keyChar=Undefined keyChar,modifiers=?,extModifiers=?,keyLocation=KEY_LOCATION_LEFT,rawCode=0,primaryLevelUnicode=0,scancode=0] on dialog0
  java.awt.event.KeyEvent[KEY_PRESSED,keyCode=87,keyText=W,keyChar='w',modifiers=?,extModifiers=?,keyLocation=KEY_LOCATION_STANDARD,rawCode=0,primaryLevelUnicode=0,scancode=0] on dialog0
  2013-02-10 19:24:28.716 java[10029:2707] Attempt to call non-applicable method "keyCode" on SyntheticEvent!
  2013-02-10 19:24:28.718 java[10029:2707] (
      0   CoreFoundation                      0x00007fff90e5f0a6 __exceptionPreprocess + 198
      1   libobjc.A.dylib                     0x00007fff9617b3f0 objc_exception_throw + 43
      2   CoreFoundation                      0x00007fff90e5ee7c +[NSException raise:format:] + 204
      3   libawt.jnilib                       0x0000000110e3564b -[SyntheticEvent keyCode] + 58
      4   libawt.jnilib                       0x0000000110e397a4 -[NSViewAWT performKeyEquivalent:] + 507
      5   AppKit                              0x00007fff938793c9 -[NSView _performKeyEquivalent:conditionally:] + 41
      6   AppKit                              0x00007fff93879512 -[NSView performKeyEquivalent:] + 166
      7   AppKit                              0x00007fff938793c9 -[NSView _performKeyEquivalent:conditionally:] + 41
      8   AppKit                              0x00007fff93879329 -[NSWindow performKeyEquivalent:] + 64
      9   AppKit                              0x00007fff93879114 -[NSApplication _handleKeyEquivalent:] + 462
      10  AppKit                              0x00007fff93c29232 -[NSWindow keyDown:] + 89
      11  Foundation                          0x00007fff91965677 __NSThreadPerformPerform + 225
      12  CoreFoundation                      0x00007fff90dde101 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
      13  CoreFoundation                      0x00007fff90dddaed __CFRunLoopDoSources0 + 445
      14  CoreFoundation                      0x00007fff90e00dc5 __CFRunLoopRun + 789
      15  CoreFoundation                      0x00007fff90e006b2 CFRunLoopRunSpecific + 290
      16  HIToolbox                           0x00007fff8b4430a4 RunCurrentEventLoopInMode + 209
      17  HIToolbox                           0x00007fff8b442e42 ReceiveNextEventCommon + 356
      18  HIToolbox                           0x00007fff8b442cd3 BlockUntilNextEventMatchingListInMode + 62
      19  AppKit                              0x00007fff93655613 _DPSNextEvent + 685
      20  AppKit                              0x00007fff93654ed2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
      21  libawt.jnilib                       0x0000000110de6fcf -[NSApplicationAWT nextEventMatchingMask:untilDate:inMode:dequeue:] + 124
      22  AppKit                              0x00007fff9364c283 -[NSApplication run] + 517
      23  libawt.jnilib                       0x0000000110de5680 +[AWTStarter startAWT:] + 1495
      24  libawt.jnilib                       0x0000000110de4ffa -[CPerformer perform] + 93
      25  Foundation                          0x00007fff91965677 __NSThreadPerformPerform + 225
      26  CoreFoundation                      0x00007fff90dde101 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
      27  CoreFoundation                      0x00007fff90ddda25 __CFRunLoopDoSources0 + 245
      28  CoreFoundation                      0x00007fff90e00dc5 __CFRunLoopRun + 789
      29  CoreFoundation                      0x00007fff90e006b2 CFRunLoopRunSpecific + 290
      30  java                                0x0000000107c97843 java + 18499
      31  java                                0x0000000107c9729a java + 17050
      32  java                                0x0000000107c94a98 java + 6808
  )
  </code></pre>
  
  <p>The first two things are the println statements, which seem to be normal. I have no clue what the SyntheticEvent stuff means, and have been unsuccessful with Google. Can anybody point me in the right direction - what's wrong with this? The window disposes normally after this.</p>
  
  <p>Thanks!</p>