[LibGDX] Using the same input key in a pause and play state

Hi,

I’m attempting to create a Pause state for my game, however its not actually a state, its just an overlay (to make it easier to resume) but the problem I’m having is when you press the escape key, it goes into the pauseState and then when you try to go back to the play state it immediately pauses again because the escape key is how you enter and exit it. I need to know how to make it so that when you press the escape key, it will only register the press once and then ignore that press in the new state.

(At the moment the game is mostly based off of ForeignGuyMike’s Block Bunny tutorial)

This is a snippet of the GameStateManager code

	private PauseState pauseState;
	public boolean paused;

	public void update(float dt) {
		gameStates.peek().update(dt);
		if(paused) {
			pauseState.update(dt);
			System.out.println("updated!");

			return;
		}
	}
	
	public void render() {
		gameStates.peek().render();
		if(paused) {
			System.out.println("paused gsm");
			pauseState.render();

			return;
		}
	}
	
	public void setPaused(boolean b) { paused = b; System.out.println("this works");}

This is the input for the pausestate code (It enters the pausestate fine, but when you press escape again it flashes back to play state and then back to the pausestate)

	public static boolean pEscape = false;
	public void handleInput() {
			if(Play.escape) {
				pEscape = false;
			}	
			if(SJInput.isPressed(SJInput.ESCAPE)) { 
				pEscape = true;
			}
			
			if(pEscape) {
				gsm.setPaused(false);
			}

	public void update(float dt) {
			handleInput();
	}

And here is the play code to enter the pauseState

	public static boolean escape = false;

			if(SJInput.isPressed(SJInput.ESCAPE)) {
				escape = true;
			}
			if(escape) {
				gsm.setPaused(true);
			}

Any ideas would be greatly appreciated. (I’ve tried taking it up with Mike, and he’s been quite helpful, but I don’t want to keep annoying him with my constant barrages of questions :P)

Thanks