question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LWJGL2 InputProcessor keyTyped() gets stuck after setWindowedMode() & setFullscreenMode()

See original GitHub issue

Issue details

I’m trying to make the game switch from windowed / fullscreen modes by pressing ALT+ENTER. It works fine except after that, keyTyped() method gets fired indefinitely until another key is pressed. Could be because keyUp() never gets called but I don’t need that. (This does not happen on LWJGL3 backend)

Reproduction steps/code

Partial ApplicationListener & InputProcessor:

class TestGame implements ApplicationListener, InputProcessor {
    private static final String TAG = "TestGame";

    @Override
    public void create() {
        Gdx.input.setInputProcessor(this);
    }

    @Override
    public void render() {
        if(Gdx.input.isKeyPressed(com.badlogic.gdx.Input.Keys.ALT_LEFT) &&
                Gdx.input.isKeyPressed(com.badlogic.gdx.Input.Keys.ENTER)) {
            if(Gdx.graphics.isFullscreen()) {
                Gdx.app.log(TAG, "Switching to windowed mode");
                Gdx.graphics.setWindowedMode(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            else {
                Gdx.app.log(TAG, "Switching to fullscreen mode");
                Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
            }
        }
    }

    @Override
    public boolean keyDown(int keycode) {
        Gdx.app.log(TAG, "keyDown: " + keycode);
        return false;
    }

    @Override
    public boolean keyUp(int keycode) {
        Gdx.app.log(TAG, "keyUp: " + keycode);
        return false;
    }

    @Override
    public boolean keyTyped(char character) {
        Gdx.app.log(TAG, "keyTyped: " + (int)character);
        return false;
    }
}

LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
Graphics.DisplayMode display = LwjglApplicationConfiguration.getDesktopDisplayMode();
config.width = display.width;
config.height = display.height;
config.fullscreen = false;
new LwjglApplication(new TestGame(), config);

Version of LibGDX and/or relevant dependencies

1.9.9-SNAPSHOT

Stacktrace

“keyTyped: 13” should not happen repeatedly after switching modes:

[TestGame] keyDown: 57
[TestGame] keyTyped: 0
[TestGame] keyDown: 66
[TestGame] keyTyped: 13
[TestGame] Switching to fullscreen mode
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyDown: 57
[TestGame] keyTyped: 0
[TestGame] keyDown: 66
[TestGame] keyTyped: 13
[TestGame] Switching to windowed mode
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13
[TestGame] keyTyped: 13

Please select the affected platforms

  • Android
  • iOS (robovm)
  • iOS (MOE)
  • HTML/GWT
  • Windows
  • Linux
  • MacOS

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
code-disastercommented, Aug 17, 2018

Your input processor doesn’t do anything (besides logging).

Gdx.input.isKeyPressed() is true as long as you hold down those keys. You run this on render(), which means you are trying to toggle fullscreen mode at 60 (or more) frames per second.

A more practical approach is to trigger the toggle on keyDown() or keyUp() in your listener. Since it’s not advised to change modes in callbacks/event handlers, you should use postRunnable() so that the mode switch is done at start of the next render frame.

0reactions
someguy233commented, Aug 18, 2018

You’re right. Moving the mode switch to keyUp() solves the issue. But, there is still no keyUp event for the ALT key. But that’s fine since keyTyped() doesn’t get called for the ALT key anyway.

Thanks!.

        @Override
        public boolean keyUp(int keycode) {
            Gdx.app.log(TAG, "keyUp: " + keycode);
            if(keycode == Input.Keys.ENTER && Gdx.input.isKeyPressed(Input.Keys.ALT_LEFT)) {
                if(Gdx.graphics.isFullscreen()) {
                    Gdx.app.log(TAG, "Switching to windowed mode");
                    Gdx.graphics.setWindowedMode(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
                }
                else {
                    Gdx.app.log(TAG, "Switching to fullscreen mode");
                    Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
                }
            }
            return false;
        }
Read more comments on GitHub >

github_iconTop Results From Across the Web

LABCESEX1 | PDF | Shader | Ios - Scribd
Anchor rendering in upper left corner when canvas is resized. Fixed NinePatch copy constructor and tint() using padding from the patch when it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found