public void keyPressed(KeyEvent e)
	{
		int key = e.getKeyCode();

		recentlySaved=false;

		if(encounter||trainerEnc)
			return;
			
		if(showCredits)
			return;

		URL url = Pokemon.class.getResource("Sprites/pokemon/Right/" + Pokedex.speciesToString(Pokedex.getSpecies(pokedexInt)) + ".png");
		pokedexImg = Toolkit.getDefaultToolkit().createImage(url);

		if(playingMinigame)
		{
			switch(key)
			{
				//Down
				case 40:
					if(minigameInt<2)
						minigameInt++;
					break;
				//Up
				case 38:
					if(minigameInt>0)
						minigameInt--;
					break;
				//Spacebar
				case 32:
					invokeMinigame=true;
					performingAction=true;
					break;
				//Backspace
				case 8:
					playingMinigame=false;
					break;
			}

			return;
		}

		if(flyMenu)
		{
			switch(key)
			{
				//Down
				case 40:
					if(flyMenuInt<flyAreas.length-1)
						flyMenuInt++;
					break;
				//Up
				case 38:
					if(flyMenuInt>0)
						flyMenuInt--;
					break;
				//Spacebar
				case 32:
					performingAction=true;
					break;
				case 'f':
				case 'F':
					flyMenu=false;
					break;
			}
			return;
		}

		if(onComp)
		{
			switch(key)
			{
				case 'W':
				case 'w':
					compMode="Withdraw";
					compInt=0;
					break;
				case 'D':
				case 'd':
					compMode="Deposit";
					compInt=0;
					break;
				case 'R':
				case 'r':
					compMode="Release";
					compInt=0;
					break;
				case 8:
					onComp=false;
					return;
			}

			if(compMode.equals("Withdraw"))
			{
				switch(key)
				{
					//Down
					case 40:
						if(compInt<11)
							compInt++;
						break;
					//Up
					case 38:
						if(compInt>0)
							compInt--;
						break;
					//Left
					case 37:
						if(compBox>0)
							compBox--;
						break;
					//Right
					case 39:
						if(compBox<9)
							compBox++;
						break;
					//Spacebar
					case 32:
						boolean canWithdraw=true;
						int numPo=0;

						for(int i=0; i<6; i++)
						{
							if(partyPokemon[i]!=null)
								numPo++;
						}

						canWithdraw=numPo<6;

						if(canWithdraw&&pcPokemon[12*compBox+compInt]!=null)
						{
							for(int i=0; i<6; i++)
							{
								if(partyPokemon[i]==null)
								{
									partyPokemon[i]=pcPokemon[12*compBox+compInt];
									pcPokemon[12*compBox+compInt]=null;
								}
							}
						}
						break;
				}
			}
			else if(compMode.equals("Deposit"))
			{
				switch(key)
				{
					//Down
					case 40:
						if(compInt<5)
							compInt++;
						break;
					//Up
					case 38:
						if(compInt>0)
							compInt--;
						break;
					//Spacebar
					case 32:
						boolean canDeposit=true;
						int numPo=0;

						for(int i=0; i<6; i++)
						{
							if(partyPokemon[i]!=null)
								numPo++;
						}

						canDeposit=numPo>1;

						if(canDeposit&&partyPokemon[compInt]!=null)
						{
							for(compBox=0; compBox<10; compBox++)
							{
								for(int i=0; i<12; i++)
								{
									if(pcPokemon[12*compBox+i]==null)
									{
										pcPokemon[12*compBox+i]=partyPokemon[compInt];
										partyPokemon[compInt]=null;
										for(int j=1; j<6; j++)
										{
											if(partyPokemon[j-1]==null&&partyPokemon[j]!=null)
											{
												partyPokemon[j-1]=partyPokemon[j];
												partyPokemon[j]=null;
											}
										}
										return;
									}
								}
							}
						}
						break;
				}
			}
			else if(compMode.equals("Release"))
			{
				switch(key)
				{
					//Down
					case 40:
						if(compInt<11)
							compInt++;
						break;
					//Up
					case 38:
						if(compInt>0)
							compInt--;
						break;
					//Left
					case 37:
						if(compBox>0)
							compBox--;
						break;
					//Right
					case 39:
						if(compBox<9)
							compBox++;
						break;
					//Spacebar
					case 32:
						pcPokemon[12*compBox+compInt]=null;
						break;
				}
			}

			return;
		}

		if(CONNECTED)
		{
			switch(key)
			{
				//Down
					case 40:
						if(offerIndex<5&&partyPokemon[offerIndex+1]!=null)
							offerIndex++;
						break;
					//Up
					case 38:
						if(offerIndex>0)
							offerIndex--;
						break;
				//Spacebar
				case 32:
					tradeConfirm=!tradeConfirm;
					break;
			}
			return;
		}

		switch (key)
		{
			//Up
			case 38:
				if(paused)
				{
					switch(pauseMenuInt)
					{
						case 0:
							if(pokedexInt>1)
								pokedexInt--;
							url = Pokemon.class.getResource("Sprites/pokemon/Right/" + Pokedex.speciesToString(Pokedex.getSpecies(pokedexInt)) + ".png");
		    				pokedexImg = Toolkit.getDefaultToolkit().createImage(url);
							break;
						case 1:
							if(pokemonMenuInt>0)
								pokemonMenuInt--;
							break;
					}
				}
				else
				{
					//Change Direction
					direction=90;
					moving=true;
				}
				break;
			//Down
			case 40:
				if(paused)
				{
					switch(pauseMenuInt)
					{
						case 0:
							if(pokedexInt<151)
								pokedexInt++;
							url = Pokemon.class.getResource("Sprites/pokemon/Right/" + Pokedex.getSpecies(pokedexInt) + ".png");
		    				pokedexImg = Toolkit.getDefaultToolkit().createImage(url);
							break;
						case 1:
							if(pokemonMenuInt<5&&partyPokemon[pokemonMenuInt+1]!=null)
								pokemonMenuInt++;
							break;
					}
				}
				else
				{
					//Change Direction
					direction=270;
					moving=true;
				}
				break;
			//Left
			case 37:
				if(paused)
				{
					if(pauseMenuInt>0)
						pauseMenuInt--;
				}
				else
				{
					//Change Direction
					direction=180;
					moving=true;
				}
				break;
			//Right
			case 39:
				if(paused)
				{
					if(pauseMenuInt<pauseMenu.length-1)
						pauseMenuInt++;
				}
				else
				{
					//Change Direction
					direction=0;
					moving=true;
				}
				break;
			case 'S':
			case 's':
				if(DEBUG)
				{
					surfing=true;
				}
				break;
			case 'T':
			case 't':
					System.out.println("X: " + location.x);
					System.out.println("Y: " + location.y);
					System.out.println("Tile: "+currentArea[location.x][location.y]);
				break;
			case 'H':
			case 'h':
				if(cartographer)
				{
					horizontalFill();
				}
				break;
			case 'b':
			case 'B':
				if (cartographer)
				{
					int x = 0;
					switch(tileSet)
					{
						case INDOORS:
							x=assignTileIntIndoors;
							break;
						case OUTDOORS:
							x=assignTileIntOutdoors;
							break;
					}
					try
					{
						currentArea[location.x][location.y]=x;
						currentArea[location.x][location.y+1]=x;
						currentArea[location.x+1][location.y]=x;
						currentArea[location.x+1][location.y+1]=x;
					}
					catch(IndexOutOfBoundsException ee)
					{
						System.out.println("Can't go outside of boundary");
					}

				}
				else
				{
					if(Inventory.hasItem(new Item(Item.Type.BICYCLE,1))&&!surfing)
					{
						if(!bicycling)
						{
							performingAction=true;
							invokeBicycle=true;
						}
						else
						{
							bicycling=false;
							bikeSong.stop();
							bgm.loop();
						}
					}
				}
				break;
			case 'z':
			case 'Z':
				if(cartographer)
				{
					switch (tileSet)
					{
						case OUTDOORS:
							if(assignTileIntOutdoors>0)
							assignTileIntOutdoors--;
							break;
						case INDOORS:
							if(assignTileIntIndoors>0)
							assignTileIntIndoors--;
							break;
					}
				}
				break;
			case 'x':
			case 'X':
				if(cartographer)
				{
					switch (tileSet)
					{
						case OUTDOORS:
							if(assignTileIntOutdoors<tileImgOutdoors.length-1)
							assignTileIntOutdoors++;
							break;
						case INDOORS:
							if(assignTileIntIndoors<tileImgIndoors.length-1)
							assignTileIntIndoors++;
							break;
					}
				}
				break;
			case 'c':
			case 'C':
				if (cartographer)
				{
					int assignTileInt = 0;
					switch (tileSet)
					{
						case INDOORS:
							if (currentArea[location.x][location.y] < tileImgIndoors.length)
							assignTileIntIndoors=currentArea[location.x][location.y];
							break;
						case OUTDOORS:
							if (currentArea[location.x][location.y] < tileImgOutdoors.length)
							assignTileIntOutdoors=currentArea[location.x][location.y];
							break;
					}
				}
				break;
			case 'f':
			case 'F':
				if((Inventory.hasItem(new Item(Item.Type.HM,1,2)))&&!paused&&!surfing&&Mechanics.hasFly(partyPokemon)&&!flyMenu&&tileSet==OUTDOORS)
				{
					getFlyAreas();
					flyMenuInt=0;
					flyMenu=true;
				}
				else
				{
					flyMenu=false;
				}
				break;
			case 'm':
			case 'M':
				if (!invokeMap)
				{
					invokeMap=true;
					performingAction=true;
				}
				break;
			//Spacebar
			case 32:
				if(titleScreen)
				{
					titleScreen=false;
					return;
				}

				if(paused)
				{
					switch(pauseMenuInt)
					{
						case 0:
							break;
						case 1:
							if(togglingPokemon)
							{
								Pokemon temp=new Pokemon(Pokemon.Species.BULBASAUR);
								temp=partyPokemon[toggleIndexToSwitch];
								partyPokemon[toggleIndexToSwitch]=partyPokemon[pokemonMenuInt];
								partyPokemon[pokemonMenuInt]=temp;
								loadPokemonImages();
							}
							else
							{
								toggleIndexToSwitch=pokemonMenuInt;
							}
							togglingPokemon=!togglingPokemon;
							break;
						case 2:
							Battle.user=partyPokemon;
							InventoryWindow iWin=new InventoryWindow();
							iWin.openInventory(InventoryWindow.State.OVERWORLD);
							for(int i=0; i<6; i++)
							{
								partyPokemon[i]=Battle.getPokemon(i);
							}
							break;
						case 3:
							break;
						case 4:
							save();
							break;
					}
				}
				else
				{
					if (!cartographer)
					performingAction=true;

					else
					{
						switch(tileSet)
						{
							case INDOORS:
								currentArea[location.x][location.y] = assignTileIntIndoors;
								break;
							case OUTDOORS:
								currentArea[location.x][location.y] = assignTileIntOutdoors;
								break;
						}
					}
				}
				break;
			//Enter
      		case 10:
      			if(!onComp&&!transition&&!trainerEnc&&!cartographer&&!moving)
      			{
      				paused=!paused;
      				togglingPokemon=false;
      				currentObjective=getCurrentObjective();
      			}

      			loadPokemonImages();
      		 	url = Pokemon.class.getResource("Sprites/pokemon/Right/" + Pokedex.getSpecies(pokedexInt) + ".png");
		    	pokedexImg = Toolkit.getDefaultToolkit().createImage(url);
      			break;
      		//0
      		case 48:
      			if(DEBUG)
      			cartographer=!cartographer;
      			//saveTileSet();
				break;
		}
	}