Java 类org.lwjgl.glfw.GLFWKeyCallbackI 实例源码
项目:candlelight
文件:KeyboardHandler.java
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;
}
}