No ENTER keycode?

Started by Orly, August 14, 2019, 12:13:56

Previous topic - Next topic

Orly

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.

KaiHH

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();
  }
}

Orly

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..?

KaiHH

If you can, you should definitely move to LWJGL 3. It uses GLFW 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.