Hello Guest

Mouse.getEventButtonState() release

  • 2 Replies
  • 13992 Views
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


*

Offline kappa

  • *****
  • 1319
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());
}
}
« Last Edit: November 24, 2013, 22:11:46 by kappa »

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;
}