The InputListener
http://pastebin.java-gaming.org/c2752769f25
Action.java
http://pastebin.java-gaming.org/275268f9528
Using it in a game
public void init(){
new InputListener(this);
}
public void update(){
if (Keyboard.isPressed(KeyEvent.VK_SPACE)){
// Space is pressed
}
// Initial press of A
Keyboard.setDetectionType(KeyEvent.VK_A, Action.Behaviour.INITIAL_DETECT);
if (KeyBoard.isPressed(KeyEvent.VK_A){
// A is pressed for the first time.
}
// Mouse click
if (Mouse.isClicked()){
// A mouse click happened.
}
// Mouse press
if (Mouse.isPressed(Mouse.MOUSE_BUTTON_1)){
// The left mouse button is pressed
}
}
Sorry for no comments in the code. If you want the implementation with comments, see https://code.google.com/p/game-engine-for-java/source/browse/#git%2Fsrc%2Fcom%2Fgej%2Finput