Fix #7429: Prevent stuck keys when game window loses focus
Summary
Fixes a bug where keyboard inputs could become stuck when the user unfocus the window.
Changes
Ensures keys pressed are properly handled when the editor loses focus.
Cleans up event listeners to avoid lingering state when switching scenes.
Motivation
The issue led to confusing and frustrating user experience when keys (like arrow keys or shortcuts) would appear stuck after interacting with other windows or tabs. This fix restores reliable keyboard behavior.
Demo
https://github.com/user-attachments/assets/29a4721c-1a92-4536-a391-f41b30a4f59f
Hi @4ian — Travis CI is failing with a CXXABI_1.3.11 not found error. It seems related to clang (v18.1.8) being used with a downgraded libstdc++6 (v5.4.0), which breaks compiler compatibility.
My PR only touches a JS file (runtimegame-pixi-renderer.ts), so the build failure seems to be caused by CI config, not the code but I'm not entirely sure.
Could you take a look or advise on next steps? Thanks!
Hi! Thanks for the PR. You can safely ignore Travis CI errors - the CI is out of date and we'll probably remove/replace it.
For the changes, do you think we should consider these keys as "discarded" (like you did) or simulate that they are "released"? For example, in this branch we added a "releaseAllPressedKeys":
https://github.com/4ian/GDevelop/blob/726d3a88161142126f97e1f33098f0ddb9263647/GDJS/Runtime/inputmanager.ts#L151-L161
From the point of view of the game creator, I'm not sure if we should discard the keys (meaning a key could be pressed, but then never released, and then pressed again, from the point of view of the game) or simulate they are released (so we would keep the invariant that "one key press will be followed, at some point, by a key release" - but this would be simulated so it's also not entirely true). What do you think?