title: How to know how many milliseconds Key is pressed in java
body: <p>I want to find out the time in milliseconds that some key is pressed in java, but my result always prints a different number even though I pressed the key for less that one second or more. 
  For Example If I pressed for less that one seconds shows 30, 45 or 98 and if I pressed for 3 seconds shows 35 , 50 , 120
  I tried this code</p>
  
  <pre><code>long keyPressedMillis;
  long keyPressLength;
  </code></pre>
  
  <p>.</p>
  
  <pre><code>public void keyPressed(KeyEvent arg0) {
      // TODO Auto-generated method stub
      int codigo = arg0.getKeyCode();
      if(codigo == KeyEvent.VK_SPACE)
      {
             keyPressedMillis = System.currentTimeMillis();           
      }
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>public void keyReleased(KeyEvent arg0) {
      // TODO Auto-generated method stub
      int codigo = arg0.getKeyCode();
      if(codigo == KeyEvent.VK_SPACE)
      {
             keyPressLength = System.currentTimeMillis() -keyPressedMillis;           
             System.out.println(keyPressLength);          
      }
  }
  </code></pre>