0

I have a Problem with Java and lwjgl the Import:

import org.lwjgl.input.Keyboard;

won't work. I have added the jars:

lwjgl-glfw.jar
lwjgl-opengl.jar
lwjgl-stb.jar
lwjgl.jar
joml
coolian
  • 33
  • 8

2 Answers2

1

You are using LWJGL 3 right? LWJGL 3 doesn't have a Keyboard or Mouse class, you have to use the functions provided by GLFW. http://www.glfw.org/docs/latest/input_guide.html

Wendelin
  • 2,354
  • 1
  • 11
  • 28
  • jes but i dont understand the keycallback so now i have downgraded to lwjgl 2 – coolian Oct 25 '17 at 18:53
  • You should probaby use lwjgl 3, because its newer and better, also key callbacks are very simple. I can give you my implementation if you want to know how to do it or don't want to do it yourself – Wendelin Oct 27 '17 at 14:48
  • KeyCallbacks not easy i have tried it much times but i dont understand it now i have downgraded my Project to lwjgl 2 – coolian Nov 13 '17 at 11:29
0

As Wendelin said, if you're using LWJGL 3, the import you try to use, is there no longer. In LWJGL 3, you set callbacks. A callback, is a function/method that you create, and LWJGL executes. If for example, you set a close callback, your function/method is called when LWJGL has detected that the user wants to quit.

I can show you two examples of this: closing and iconifying.

import static org.lwjgl.glfw.GLFW.glfwSetWindowCloseCallback;
import static org.lwjgl.glfw.GLFW.glfwSetWindowIconifyCallback;

public class Program {

    public static void main(String[] arguments) {
        glfwSetWindowCloseCallback(display, (NULL) -> {
            System.out.prinln("User tried to quit")
        });

        glfwSetWindowIconifyCallback(display, (window, iconified) -> {
            System.out.println("User tried to iconify the window")
        });
    }
}

The first argument to the callback function setter, display, is the display the callback will be set on. You should check out the link Wendelin provided, for more information.

If you are using LWJGL 2, or the imports aren't working in LWJGL 3, you've probably not attached the framework to your project correctly. If this is the case, you'll simply have to fix that problem. If you're in IntelliJ IDEA (MacOS), you can go to File -> Project Structure -> Project Settings -> Libraries, and click on + to add a new framework to your project.