title: Simulate key type with Java Robot
body: <p>I write a method to simulate key press from KeyEvent, like below:</p>
  
  <pre><code>private Robot robot(){
          if(robot==null){
              try {
                  return new Robot();
              } catch (AWTException e) {
                  throw new RuntimeException("Failed to create instance of Robot");
              }
          }else{
              return robot;
          }
      }
  
  public void sendKeyEvent(KeyEvent evt) throws IOException {
          int type = evt.getID();
          if(type == KeyEvent.KEY_PRESSED){
              if(evt.isShiftDown()){
                  robot().keyPress(KeyEvent.VK_SHIFT);
              }
              robot().keyPress(evt.getKeyChar());
          }else if(type == KeyEvent.KEY_RELEASED){
              robot().keyRelease(evt.getKeyChar());
              if(evt.isShiftDown()){
                  robot().keyRelease(KeyEvent.VK_SHIFT);
              }
          }
      }
  </code></pre>
  
  <p>When this method received press 'A' key event, it could type 'A'.</p>
  
  <pre><code>java.awt.event.KeyEvent[KEY_PRESSED,keyCode=0,keyText=Unknown keyCode: 0x0,keyChar='A',modifiers=Shift,extModifiers=Shift,keyLocation=KEY_LOCATION_UNKNOWN]]
  </code></pre>
  
  <p>But the problem is when it received this KeyEvent(press 'a'), it acturaly pressed "1". </p>
  
  <pre><code>java.awt.event.KeyEvent[KEY_PRESSED,keyCode=0,keyText=Unknown keyCode: 0x0,keyChar='a',keyLocation=KEY_LOCATION_UNKNOWN]]
  </code></pre>
  
  <p>Could anyone tell me what wrong with this method?</p>