I want to addKeyListener
to a JPanel
but when I press two keys at the same time, just one of them executes. What is the solution to this problem - press two keys at the same time?
I have a class that extends JPanel
this.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_W) {
upPlayer2();
} if (e.getKeyCode() == KeyEvent.VK_A ){
leftPlayer2();
}
}
});
Thanks.