I have this code right here (using lwjgl but that should be moot) to try and pause a game when pressing the esc key. I use an ArrayList with the keys to keep track of what is pressed and what isn't.
public List<Integer> keys = new ArrayList<Integer>();
public void get() {
if (isKeyDown(KEY_ESCAPE) && !keys.contains(KEY_ESCAPE)) {
keys.add(KEY_ESCAPE);
keyEscape();
}
}
public void rem() {
if (!isKeyDown(KEY_ESCAPE) && keys.contains(KEY_ESCAPE))
keys.remove(KEY_ESCAPE);
}
private void keyEscape() {
Screen.paused ^= true;
}
This is called by the loop, which does get()
and rem()
one right after another in the loop, in that order. This gives me an awesome java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at keys.remove(KEY_ESCAPE);
when I let go of ESC.
Anyone have any insight to share?