org.lwjgl.glfw.GLFWKeyCallback Java Examples

The following examples show how to use org.lwjgl.glfw.GLFWKeyCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlfwKeyInputVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void initialize() {
    if (!context.isRenderable()) {
        return;
    }

    glfwSetKeyCallback(context.getWindowHandle(), keyCallback = new GLFWKeyCallback() {
        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            scancode = GlfwKeyMap.toJmeKeyCode(key);
            if( key == GLFW_KEY_LEFT_SHIFT || key == GLFW_KEY_RIGHT_SHIFT ) {
                shift_pressed = (action == GLFW_PRESS);
            } else if( key >= 'A' && key <= 'Z' && !shift_pressed ) {
                key += 32; // make lowercase
            } else if( key >= 'a' && key <= 'z' && shift_pressed ) {
                key -= 32; // make uppercase
            }
            final KeyInputEvent evt = new KeyInputEvent(scancode, (char) key, GLFW_PRESS == action, GLFW_REPEAT == action);
            evt.setTime(getInputTimeNanos());
            keyInputEvents.add(evt);
        }
    });

    glfwSetInputMode(context.getWindowHandle(), GLFW_STICKY_KEYS, 1);

    initialized = true;
    logger.fine("Keyboard created.");
}
 
Example #2
Source File: Input.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public GLFWKeyCallback getKeyboardCallback() {
	return keyboard;
}