HOW DO I KNOW IF I PRESS ENTER IF I DON'T GET A KEYCODE??
Yeah, hi. The title says all. I've been navigating through all the Keyboard keycodes, but I just can't find the ENTER key. Maybe you should use Keybaord.KEY_NUMPADENTER, but I'm on a laptop so I don't have a numpad. I checked the internet, and there are just no answers. I also tried to spam "System.out.println(Keyboard.getEventKey);" : if I press a random key, the correct code is logged. But if I press enter, it keeps logging 0, like if no key aws pressed.
The key code you are looking for is called KEY_RETURN. Example:
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class InputExample {
public static void main(String[] argv) throws Exception {
Display.setDisplayMode(new DisplayMode(800, 600));
Display.create();
while (!Display.isCloseRequested()) {
while (Keyboard.next()) {
if (Keyboard.getEventKeyState())
if (Keyboard.getEventKey() == Keyboard.KEY_RETURN)
System.out.println("RETURN Key Pressed");
else if (Keyboard.getEventKey() == Keyboard.KEY_RETURN)
System.out.println("RETURN Key Released");
}
Display.update();
}
Display.destroy();
}
}
Already tried, still not working. I'm running the process from a Linux Mint laptop, maybe the problem is that that enter key is not supported? As I already said, if I check the int of the current pressed key, and I press ENTER, it displays me a value of 0, but if I press other keys, the correct integer is being displayed. That means LWJGL is unable to detect my enter key..?
If you can, you should definitely move to LWJGL 3 (https://www.lwjgl.org/download). It uses GLFW (https://www.glfw.org/) for input and window/context handling and is actively maintained, much unlike LWJGL 2, which is being phased out for a few years now and won't be developed anymore. Chances are that GLFW's implementation may be more robust and takes better care of keyboard mappings.