title: how long is a key being pressed in java
body: <p>well i'm making a program and it should do something after the key 'f' was pressed for 3 seconds, if it wasn't pressed for 3 seconds then it shouldn't do anything, i know how to know if a key is being pressed and released but i don't find any method to know the time of being pressed </p>
  
  <pre><code>private void formKeyPressed(java.awt.event.KeyEvent evt) {                                
      // to know if a key is being pressed
  
  }
  private void formKeyReleased(java.awt.event.KeyEvent evt) {                                
      // to know when a key is released
  
  }  
  </code></pre>
  
  <p><strong>Edit:</strong> 
  Nevermid about those answers, it didn't work. to make it work i had to do this:</p>
  
  <pre><code>private long keyPressedMillis;
  private boolean alreadyPassed==false;
  ...
  private void formKeyPressed(KeyEvent event) {
  if(alreadyPassed==false)
  keyPressedMillis = System.currentTimeMillis()
  alreadyPassed=true;
  }
  private void forKeyReleased(KeyEvent event) {
  long keyPressLength = System.currentTimeMillis() - keyPressedMillis;
      alreadyPassed=false;
      System.out.println("Key Pressed "+keyPressLenght+" ms");
  
  }
  </code></pre>