JOGL KeyListener not functioning properly

I have been having a problem with the JOGL KeyListener where if I hold down a key, it would register the key as pressed for around 1 second, then it would start quickly switching back and forth between pressed and unpressed. However, if I hold more than one key at once, sometimes the key listener "forgets" about one of the keys and keeps it held down (like it should) while releasing the other one (when it shouldn't).

Here is the relevant code in the class:

import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener;

import java.util.HashSet;
import java.util.Set;

public class KeyInput implements KeyListener {
private static Set<Short> key=new HashSet<Short>();
public void keyPressed(KeyEvent keyEvent) {
}

public void keyReleased(KeyEvent keyEvent) {
key.remove(keyEvent.getKeyCode());
System.out.println("removed " +keyEvent.getKeyChar());
}

public static boolean getKey(short k){
return key.contains(k);
}
}


I tried using other methods of storing the keys to no avail. How should I fix it so that it properly registers and remembers held down keys? I tried a different program with Swing and it worked fine. It has the exact same code as shown here.

• Can you rule out hardware or OS issues? For example, you can use that many keys normally in other programs. Is there a way that you can consistently reproduce it with, say, two keys? – Jay Mar 18 '19 at 2:45
• @Jay I have a different program using the Swing framework and it works fine on the same PC. – ImTheSquid Mar 18 '19 at 12:15

if(keyEvent.isAutoRepeat()){

This would go in the keyReleased method.