KeyboardHandler(Window window) { this.window = window; GLFWKeyCallbackI keyCallback = null; try { keyCallback = GLFW.glfwSetKeyCallback(this.window.handle(), (handle, key, scancode, action, mods) -> { ButtonInput input = this.getButton(key); if (input != null) { if (action == GLFW.GLFW_RELEASE) { input.release(); } else if (action == GLFW.GLFW_PRESS) { input.press(); } else { //Ignore repeating input... } } }); if (keyCallback != null) { throw new IllegalStateException("another keyboard handler is already registered!"); } } catch (Exception e) { //Reset to previous state GLFW.glfwSetKeyCallback(this.window.handle(), keyCallback); throw e; } }