I would like to know how do I get the following actions using LWJGL's Mouse class:
- When the mouse scroll wheel is scrolled down
- When the mouse scroll wheel is scrolled up
- When the mouse scroll wheel is pressed
Thanks for the help!
As specified on the lwjgl javadoc, try calling
Mouse.getDWheel(); // Scroll amount
Mouse.isButtonDown(2); // Scroll wheel pressed?
For LWJGL 3 you may do this
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWScrollCallback;
// ...
float mouseWheelVelocity = 0;
GLFW.glfwSetScrollCallback(windowId, new GLFWScrollCallback() {
@Override public void invoke (long win, double dx, double dy) {
System.out.println(dy);
mouseWheelVelocity = (float) dy;
}
});
Replace windowId
variable with yours. Make sure it's initialized by that time. Then you can save dy
argument which shows change of the mouse wheel rotation (+1 and -1).