Checking for multiple keys pressed
so im very new to java, and i made a program where u can move a little block arround in a little world and "shoot" you move with "WASD" but the movement is very buggy, 1 very important thing is that i cant move 2 directions at the same time, i would like to be able to press both example: A and W and go that > \ way
so here is part of my code:
public void keyPressed( KeyEvent e ) {
// was the easyest way for me to get the ascii of the charather pressed in an int
keyI = e.getKeyCode() + 32;
// speed = 3
for(int i = 0; i < speed; i += 1){
//W
if (keyI == 119 && free(px, py - 1 - rectsize/2) == true){py -= 1;}
//A
if (keyI == 97 && free(px - 1 - rectsize/2, py ) == true){px -= 1;}
//S
if (keyI == 115 && free(px, py + 1 + rectsize/2) == true){py += 1;}
//D
if (keyI == 100 && free(px + 1 + rectsize/2, py ) == true){px += 1;}
}
repaint();
}
so anybody know a good way to make it detect if there is more than 1 key pressed at a time, and which ?
im not sure if this is enough, just tell me if you need the whole code.