import java.awt.event.KeyEvent; import java.awt.event.KeyListener; public class Listening implements KeyListener { @Override public void keyPressed(final KeyEvent e) { final int key = e.getKeyCode(); switch (key) { case KeyEvent.VK_D: Component.isMoving = true; Component.dir = Component.character.movementSpeed; break; case KeyEvent.VK_A: Component.isMoving = true; Component.dir = -Component.character.movementSpeed; break; case KeyEvent.VK_W: Component.isJumping = true; break; case KeyEvent.VK_K: if (Inventory.selected < Tile.invLength - 1) { Inventory.selected += 1; } else { Inventory.selected = 0; if (Inventory.selected > 0) { } } } } @Override public void keyReleased(final KeyEvent e) { final int key = e.getKeyCode(); switch (key) { case KeyEvent.VK_D: if (Component.dir == Component.character.movementSpeed) { Component.isMoving = false; } break; case KeyEvent.VK_A: if (Component.dir == -Component.character.movementSpeed) { Component.isMoving = false; } break; case KeyEvent.VK_W: Component.isJumping = false; break; } } @Override public void keyTyped(final KeyEvent e) { } }