LWJGL Forum

Programming => LWJGL Documentation => Topic started by: gouber on November 24, 2013, 21:07:15

Title: Mouse.getEventButtonState() release
Post by: gouber on November 24, 2013, 21:07:15
Hello there,
Glad I could answer the incredible confusing register question just to get my head stuck with this quick question


I have the following code.

while(Mouse.next())
{
if(Mouse.getEventButtonState()){
System.out.println(" mouse clicked");
}else
{
System.out.println("mouse released");

}
}


I started the program and my console it's getting spammed with mouse released whenever I move my mouse. Does getEventButtonState for mouse return false when the mouse moves?
Thanks

Title: Re: Mouse.getEventButtonState() release
Post by: kappa on November 24, 2013, 22:08:21
moving the mouse will also cause events, so if you just want to test mouse button events then you'll need to test that the event button is 0 or greater e.g.:

while(Mouse.next()) {
if (Mouse.getEventButton() > -1) {
if (Mouse.getEventButtonState()) {
System.out.println("PRESSED MOUSE BUTTON: " + Mouse.getEventButton());
}
else System.out.println("RELEASED MOUSE BUTTON: " + Mouse.getEventButton());
}
}
Title: Re: Mouse.getEventButtonState() release
Post by: jakubch on July 25, 2016, 13:05:30
Quote from: kappa on November 24, 2013, 22:08:21
moving the mouse will also cause events, so if you just want to test mouse button events then you'll need to test that the event button is 0 or greater e.g.:

while(Mouse.next()) {
if (Mouse.getEventButton() > -1) {
if (Mouse.getEventButtonState()) {
System.out.println("PRESSED MOUSE BUTTON: " + Mouse.getEventButton());
}
else System.out.println("RELEASED MOUSE BUTTON: " + Mouse.getEventButton());
}
}


that didnt work for me in 2.9.3. I've used this for left mouse

        private leftMousePressed ;
protected boolean mouseLeftHoldCheck() {
    if (Mouse.isButtonDown(0)) {
        if (!Mouse.getEventButtonState()) {
        System.out.println("PRESSED MOUSE BUTTON: " + Mouse.getEventButton());
        leftMousePressed = true;
return true;
        }
    }
    else if (leftMousePressed){
    System.out.println("RELEASED MOUSE BUTTON: " + Mouse.getEventButton());
    leftMousePressed = false;
    }
return false;
}