LWJGL: call a() if user presses 1, but b() if user presses ! (shift-1)
- User
LWJGL: call a() if user presses 1, but b() if user presses ! (shift-1)
Assistant
Here's how to handle keyboard input in LWJGL to distinguish between pressing "1" and "!" (Shift+1):
import org.lwjgl.glfw.*; import static org.lwjgl.glfw.GLFW.*; // In your main class or window setup public void setupKeyCallback(long window) { glfwSetKeyCallback(window, new GLFWKeyCallback() { @Override public void invoke(long window, int key, int scancode, int action, int mods) { if (action == GLFW_PRESS || action == GLFW_REPEAT) { if (key == GLFW_KEY_1) { // Check if Shift is held if ((mods & GLFW_MOD_SHIFT) != 0) { b(); // Shift+1 pressed (!) } else { a(); // Just 1 pressed } } } } }); } // Your methods private void a() { System.out.println("Method a() called - pressed 1"); } private void b() { System.out.println("Method b() called - pressed ! (Shift+1)"); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.