LWJGL Forum

Programming => General Java Game Development => Topic started by: Orly on August 14, 2019, 12:13:56

Title: No ENTER keycode?
Post by: Orly on August 14, 2019, 12:13:56
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.
Title: Re: No ENTER keycode?
Post by: KaiHH on August 14, 2019, 17:03:26
The key code you are looking for is called KEY_RETURN. Example:
Code: [Select]
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();
  }
}
Title: Re: No ENTER keycode?
Post by: Orly on August 14, 2019, 17:35:48
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..?
Title: Re: No ENTER keycode?
Post by: KaiHH on August 14, 2019, 18:03:47
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.