user8476708
user8476708

Reputation:

lwjgl import Input Classes is not working

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

Upvotes: 0

Views: 2438

Answers (2)

Andreas condemns Israel
Andreas condemns Israel

Reputation: 2338

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.

Upvotes: 0

Wendelin
Wendelin

Reputation: 2401

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

Upvotes: 0

Related Questions