I am writing the input for a Java game using LWJGL3 but I have an issue with input, when I press a key it has to be held for a fraction of a second before it is picked up. How do I make it see the input as soon as it is pressed?
public class InputManager extends GLFWKeyCallback {
private long window;
public static boolean[] keys = new boolean[65536];
public InputManager(long window){
this.window = window;
}
public void setWindow(long window){
window = window;
}
@Override
public void invoke(long window, int key, int scancode, int action, int mods) {
keys[key] = action != GLFW_RELEASE;
}
}
public class DisplayManager {
private static GLFWErrorCallback errorCallback;
private static GLFWKeyCallback keyCallback;
public static void createDisplay() {
inputManager = new InputManager(window);
GLFW.glfwSetKeyCallback(window, keyCallback = inputManager);
}
public static void updateDisplay() {
GLFW.glfwPollEvents();
if (inputManager.keys[GLFW_KEY_SPACE]){
System.out.println("Spacebar pressed.");
}
}
}