package ei.engine.input;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;

import ei.engine.util.MultiPrintStream;

/**
 * This class handles key inputs
 * @author Ziver
 */
public abstract class KeyboardInput extends Input {

	public KeyboardInput(String name) {
		super(name);
        try {
        	//init keyboard
			Keyboard.create();
		} catch (LWJGLException e) {
			MultiPrintStream.out.println("Keyboard Init Erorr: "+e);
			e.printStackTrace();
		}
	}

	/**
	 * Is not used for key input.
	 */
	public void render() {}

	/**
	 * looks if any key is presed
	 */
	public void update() {
        // Handle key hits
        while ( Keyboard.next() )  {
            // pass key event to handler
            if (Keyboard.getEventKeyState()) {
                keyDown(Keyboard.getEventKey());
            }
            else {
                keyUp(Keyboard.getEventKey());
            }
        }
		
	}
	
	/**
	 * Called by update() when any key is presed
	 */
	public abstract void keyDown(int keycode);

	/**
	 * Called by update() when any key is released
	 */
	public abstract void keyUp(int keycode);

}
