LWJGL2 InputProcessor keyTyped() gets stuck after setWindowedMode() & setFullscreenMode()
See original GitHub issueIssue 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:
- Created 5 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 onrender()
, 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.
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!.