[Slick2d] [input] Keys and mouse firing too fast

Hey I’m having an issue were, when clicking on a button or when clicking a key, the key or mouse click fires like 10 responses (restricting my game to 30fps reduces the number to that, without the fps reduction its closer to 100) I’m just wondering how I can maintain that when I click or hit a button, it with only receive one response?

heres some of my input code:

// Play button
if( ( mouseX >= 0 && mouseX <= play_button.getWidth()) && ( mouseY >= 90 && mouseY <= 90 + play_button.getHeight()) ){
	insidePlay = true;
}

if(insidePlay){
	if(playScale < 1.015f)
		playScale += scaleStep * delta;
	      	 
	if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
     		if(!isLogin) {
      	  		tryLogin = true;
      	  	} else {
      	  		sb.enterState(CodaClient.GAMEPLAYSTATE);
      	  	}
      	}
 }else{
        if(playScale > 1.0f)
      		playScale -= scaleStep * delta;
 }

EDIT: Sorry if there’s another thread with a similar question, I searched threw a few pages but wasn’t sure what this exact issue is called, so I didnt find much that helped.

In slick there are a few ways to handle input.

isMouseButtonDown / isKeyDown - This will return true if the button/key is down during that frame. This is useful for things like sprite movement, which you will want to poll every frame.

overriding keyPressed / mouseButtonPressed / etc. in BasicGame - This is more useful for the event-based input you’ll need in GUI. i.e. You just want to receive a single key stroke, or a single mouse click.

isMousePressed / isKeyPressed - This will return true if the button/key has been pressed since the last time you called this method. It’s included for convenience, so you can get the same functionality as keyPressed/mouseButtonPressed from the update() method.

To fix your problem, use one of the latter two techniques.

isMousePressed(int button) will give you one response per click

That worked, thank you very much