title: Random character generating instead of GS character, in swing when scanning GS1 data matrix barcode with a small delay
body: <p>I have created a simple swing app with input text to read the barcode and print the GS character position in output text.</p>
  <p>EX:</p>
  <p>input : 01070462616434291722010010Y0238921MA3W7J59UC2W111 (get from barcode scanner)</p>
  <p>output: GS1 on position = 32</p>
  <p>Normal swing app its working properly but when creating a small delay for Key Event processor (add Thread.sleep(2) for each key event )sometimes this output is not there because some other character is generating instead of GS character.
  ( The reason of adding delay is , in the production code synthetica is used to add look and feel in the swing app and  because of that processes there seems some delays for the key events. Therefore in this simple app forcefully add a delay just to simulate the issue. )</p>
  <p>Even thought GS is not coming sometimes but the character sequence for the GS character is very same every time</p>
  <p>GS character sequence -&gt; ALT + 0 + 0 + 2 + 9</p>
  <p>Here the printed Key pressed and release key sequence for GS character (This is just to verify the character sequence when key press and key release and not included in to the recent code )</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">Key Event</th>
  <th style="text-align: center;">Key Value</th>
  <th style="text-align: right;">Key char</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">Key Pressed</td>
  <td style="text-align: center;"></td>
  <td style="text-align: right;">65535 (ALT key)</td>
  </tr>
  <tr>
  <td style="text-align: left;">Key Pressed</td>
  <td style="text-align: center;">0</td>
  <td style="text-align: right;">48</td>
  </tr>
  <tr>
  <td style="text-align: left;">Key Released</td>
  <td style="text-align: center;">0</td>
  <td style="text-align: right;">48</td>
  </tr>
  <tr>
  <td style="text-align: left;">Key Pressed</td>
  <td style="text-align: center;">0</td>
  <td style="text-align: right;">48</td>
  </tr>
  <tr>
  <td style="text-align: left;">Key Released</td>
  <td style="text-align: center;">0</td>
  <td style="text-align: right;">48</td>
  </tr>
  <tr>
  <td style="text-align: left;">Key Pressed</td>
  <td style="text-align: center;">2</td>
  <td style="text-align: right;">50</td>
  </tr>
  <tr>
  <td style="text-align: left;">Key Released</td>
  <td style="text-align: center;">2</td>
  <td style="text-align: right;">50</td>
  </tr>
  <tr>
  <td style="text-align: left;">Key Pressed</td>
  <td style="text-align: center;">9</td>
  <td style="text-align: right;">57</td>
  </tr>
  <tr>
  <td style="text-align: left;">Key Released</td>
  <td style="text-align: center;"></td>
  <td style="text-align: right;">65535 (ALT key)</td>
  </tr>
  <tr>
  <td style="text-align: left;">Key Typed</td>
  <td style="text-align: center;"></td>
  <td style="text-align: right;">29</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>This is a correct scenario and GS character is typed as expected as in last row (Key char 29 is GS character) , but in incorrect scenario all the other key events are same but key typed character is different</p>
  <p>Here is the source code</p>
  <p>SwingApp</p>
  <pre><code>import java.awt.*;
  
  public class SwingApp {
  
      public static void main(String[] args) {
          KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(keyEvent -&gt; {
              try {
                  Thread.sleep(2);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              return false;
          });
          EventQueue.invokeLater(() -&gt; new ScannerWindow().show());
      }
  }
  </code></pre>
  <p>ScannerWindow</p>
  <pre><code>import javax.swing.*;
  import java.awt.event.KeyAdapter;
  import java.awt.event.KeyEvent;
  
  public class ScannerWindow {
  
      private int i;
      private final JFrame f;
  
      public ScannerWindow(){
          f = new JFrame();
          f.setLayout( null);
  
          JTextArea ta = new JTextArea();
  
          JTextField txt=new JTextField();
          txt.setBounds(130,20,300, 40);
          txt.addKeyListener(new KeyAdapter() {
              @Override
              public void keyTyped(KeyEvent e) {
  
                  if(e.getKeyChar() == 29){
                      ta.append(&quot;\n GS1 on position = &quot; + i);
                  }
                  i++;
              }
          });
          f.add(txt);
  
          JButton b = new JButton(&quot;Clear&quot;);
          b.addActionListener(e -&gt; {
              ta.setText(&quot;&quot;);
              txt.setText(&quot;&quot;);
              i = 0;
          });
          b.setBounds(130,80,100, 40);
          f.add(b);
  
          ta.setBounds(50, 130, 400, 300);
          f.add(ta);
  
          f.setSize(600,500);
          f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  
      }
  
      public void show()
      {
          f.setVisible(true);
      }
  }
  </code></pre>
  <p>can someone help me on this ?</p>