Mouse.getEventButtonState() release

Started by gouber, November 24, 2013, 21:07:15

Previous topic - Next topic

gouber

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


kappa

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

jakubch

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