KeyListener.java
01 package rtype;
02 
03 import org.lwjgl.input.Keyboard;
04 
05 import rtype.entity.Orb;
06 
07 public class KeyListener {
08 
09   private int keyMonitored;
10   private boolean keyMonitoredWasPressed;
11   
12   public void setKeyMonitored(int keyMonitored) {
13     this.keyMonitored = keyMonitored;
14   }
15   
16   public  void  onKeyDown(){};  // This is triggered exactly when the key is pressed.
17   public  void  keyPressed(){};  // This is triggered will the key is being pressed.
18   public  void  onKeyUp(){};    // This is triggered exactly when the key is released.
19   
20   public void checkKey()
21   {
22     if(Keyboard.isKeyDown(keyMonitored)) 
23         {
24           if(keyMonitoredWasPressed)
25             keyPressed();
26           else
27           {
28             keyMonitoredWasPressed = true;
29             onKeyDown();
30           }
31           
32         }
33         else
34           if (keyMonitoredWasPressed)
35           {
36             onKeyUp();
37             keyMonitoredWasPressed = false;
38           }
39   }
40   
41 }