package com.betato.gamedisplay;

import java.awt.MouseInfo;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;

public class InputListener implements KeyListener, MouseListener, MouseMotionListener, MouseWheelListener{
	
	// Keyboard
	public boolean[] keyState = new boolean[256];
	public boolean[] keyDown = new boolean[256];
	public boolean[] keyUp = new boolean[256];
	
	// Mouse
	public int mouseX;
	public int mouseY;
	public int mouseWheel;
	public boolean[] mouseState = new boolean[MouseInfo.getNumberOfButtons()];
	public boolean[] mouseDown = new boolean[MouseInfo.getNumberOfButtons()];
	public boolean[] mouseUp = new boolean[MouseInfo.getNumberOfButtons()];
	
	public void clear() {
		// Clear keyboard
		for (int i = 0; i < keyUp.length; i++)
		{
			keyDown[i] = false;
			keyUp[i] = false;
		}
		
		// Clear mouse
		for (int i = 0; i < mouseUp.length; i++)
		{
			mouseDown[i] = false;
			mouseUp[i] = false;
		}
	}
	
	@Override
	public void keyPressed(KeyEvent e) {
		// Avoid key repeat
		// Set keyDown if key is released
		if (!keyState[e.getKeyCode()]) {
			keyDown[e.getKeyCode()] = true;
			keyState[e.getKeyCode()] = true;
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
		keyUp[e.getKeyCode()] = true;
		keyState[e.getKeyCode()] = false;
	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseWheelMoved(MouseWheelEvent e) {
		mouseWheel = e.getWheelRotation();
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		mouseDown[e.getButton()] = true;
		mouseState[e.getButton()] = true;
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		mouseUp[e.getButton()] = true;
		mouseState[e.getButton()] = false;
	}
	
}

@@ -425,16 +425,130 @@
 ener%7B%0A%09%0A
+%09public static final int NUM_KEYS = 223;%0A%09public static final int NUM_BUTTONS = MouseInfo.getNumberOfButtons();%0A%09%0A
 %09// Keyb
@@ -585,35 +585,40 @@
 e = new boolean%5B
-256
+NUM_KEYS
 %5D;%0A%09public boole
@@ -640,27 +640,32 @@
 new boolean%5B
-256
+NUM_KEYS
 %5D;%0A%09public b
@@ -697,11 +697,16 @@
 ean%5B
-256
+NUM_KEYS
 %5D;%0A%09
@@ -827,38 +827,19 @@
 ean%5B
-MouseInfo.getNumberOfButtons()
+NUM_BUTTONS
 %5D;%0A%09
@@ -883,38 +883,19 @@
 ean%5B
-MouseInfo.getNumberOfButtons()
+NUM_BUTTONS
 %5D;%0A%09
@@ -937,39 +937,136 @@
 ean%5B
-MouseInfo.getNumberOfButtons()%5D
+NUM_BUTTONS%5D;%0A%09public boolean mouseMoved = false;%0A%09public boolean mouseDragged = false;%0A%09public boolean mouseInsideWindow = true
 ;%0A%09%0A
@@ -1134,20 +1134,16 @@
 i %3C 
-keyUp.length
+NUM_KEYS
 ; i+
@@ -1217,16 +1217,62 @@
 r mouse%0A
+%09%09mouseMoved = false;%0A%09%09mouseDragged = false;%0A
 %09%09for (i
@@ -1288,23 +1288,19 @@
  i %3C
- mouseUp.length
+NUM_BUTTONS
 ; i+
@@ -1958,45 +1958,49 @@
 %7B%0A%09%09
-// TODO Auto-generated method stub%0A%09%09
+mouseMoved = true;%0A%09%09mouseDragged = true;
 %0A%09%7D%0A
@@ -2057,45 +2057,92 @@
 %7B%0A%09%09
-// TODO Auto-generated method stub%0A%09%09
+mouseMoved = true;%0A%09%09mouseDragged = false;%0A%09%09mouseX = e.getX();%0A%09%09mouseY = e.getY();
 %0A%09%7D%0A
@@ -2298,45 +2298,33 @@
 %7B%0A%09%09
-// TODO Auto-generated method stub%0A%09%09
+mouseInsideWindow = true;
 %0A%09%7D%0A
@@ -2382,45 +2382,34 @@
 %7B%0A%09%09
-// TODO Auto-generated method stub%0A%09%09
+mouseInsideWindow = false;
 %0A%09%7D%0A

Add mouse movement events to InputListener