@Override
	public boolean dispatchKeyEvent(KeyEvent arg0) {
		//this method is called twice: once for key pressed and again for released, ignore release
		//otherwise it will try to execute the command twice
		
		if(arg0.getID() != KeyEvent.KEY_PRESSED) return false;
		
		int keyPressed = arg0.getKeyCode();
		if (keyPressed ==  KeyEvent.VK_U) undoCommand();
		else if (keyPressed == KeyEvent.VK_R) redoCommand();
		else
		{
			Command c = keyToCommandMap.get(keyPressed);
			if(c != null) if(c.execute()) saveGameState(c);
		}
		return false;
	}