LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: Mouse.getEventButtonState() release  (Read 6244 times)

gouber

  • Newbie
  • *
  • Offline Offline
  • Posts: 1
Mouse.getEventButtonState() release
« 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.
Code: [Select]
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

Logged

kappa

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1308
Re: Mouse.getEventButtonState() release
« Reply #1 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.:

Code: [Select]
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());
}
}
Logged

jakubch

  • Newbie
  • *
  • Offline Offline
  • Posts: 1
Re: Mouse.getEventButtonState() release
« Reply #2 on: July 25, 2016, 13:05:30 »

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.:

Code: [Select]
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
Code: [Select]
        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;
}
Logged