[Solved] Setting a boolean once in a infinite loop?

            Alright so let's say I press a Key to make the game be able to pause, when I press that key I want the game to be paused and have to be pressed again to un-pause. Problem is, press said key makes it pause and pause almost instantly and keep doing that. Any help? I would suppose it would have to do with having my own input listener that checks for individual presses instead of having the button held.
if(Gdx.input.isKeyPressed(Keys.ESCAPE)){
			if(gameScreen.isPaused() == true){
				gameScreen.setPaused(false);
			}
			else{
				gameScreen.setPaused(true);
			}
		}

Either use isJustPressed or a listener.

Thanks again burnt pizza. Well I had a stage with the buttons and implemented InputProcessor on my HUD class and then created an Input Multiplexer to add both the HUD class and the stage. Works perfectly :D, and to think I looked over that a while ago thinking I would have no use for it since it seemed complicated! ;D 8)

I know it’s solved already, but another option is to use Gdx.input.isKeyJustPressed(Keys.ESCAPE). It’s meant for polling, but it’s not preferred over an event listener.

And for the sake of completion, if the above solutions didn’t exist, we could do this ourselves by setting a flag when we press the key, and only run the event if this flag isn’t set. The flag is unset when the key is unpressed.

A flag? So just another boolean? Wouldn’t that make the class pretty clunky if you have multiple booleans devoted to running methods once?

The way you have it there’s already multiple if statements devoted to it…

I use a similar system for things like key input , I dont want the person to spam in 50 letters just by tapping , a flag boolean is set when the key is pressed , if its true then do not call the handler function , call the function on the keypress then thats it. Then detect when the key is no longer pressed and reset this flag to false . Simples.