Engine still thinks a key is being pressed after losing window focus

After experimenting with many different ways to solve this problem, I came to the conclusion that it must be an engine bug. I even checked other games made with GDevelop on itch.io and found that they all had the same issue:

While running a game in windowed mode, if you lose focus while pressing a key, then release the key and refocus the game window, the game still thinks you’re still pressing the key even if you’re not anymore, and it will not stop until you press the same key again.

For example, you are pressing the Right key to make the character run to the right and, while you are doing that, you click out of the game window. If you come back to the game, the character is still moving to the right, because the game still thinks that you are holding Right, and it will not stop until you press the Right key again.

Here’s a video to show better this bug in action:

So far this has been my only problem with the engine, so hopefully it can be fixed in future updates.

I believe key release is same action as key pressed
Which means it checks if key is pressed and was released
It does not ONLY check if key is not pressed

But literally if key is actively being pressed and at some moment being released

Since you do release action while not in window focus your game can’t register it
So it waits for action where key is still actively being pressed and released
That’s why you need to press it again and release it after re focus

Solution would be either to check if key is NOT being pressed with inverted condition for key pressed or actually use NOT condition

This would check if key is pressed or not

And not if key was JUST released

I seen exact same thing happens in office buildings with gates which required your ID cards to let you pass

Now thing is you need to scan your ID card to pass the gates INSIDE the building but you also need to scan ID card when you are inside for gate to open when you want to leave building
Meaning you have these devices on each side one for entrance and one for exit

Now imagine you are scanning your ID card to get inside and you are in
But you jump off window and you wanna enter building again
So you scan your ID card at entrance but it won’t let you in
Because for system you are still inside building so you can’t enter 2nd time
You need to first exit building (scan ID card from inside building side)
Then you can enter it again by scanning ID card from outside by entrance
(Same situation with your focus you need to regain focus and press and release key for it to register it being released)

It is not a bug it is how it is designed and expect behavior

1 Like

First of all, thanks for the help.

I’ve tried using both the NOT conditions and inverted conditions for the keys, just like you said, but unless I did something wrong, the problem still persisted.

Also, I have to disagree about this being an expected behavior. Like I said before, I tested other games made with GDevelop, INCLUDING the templates provided by the engine, and I they experience this exact same thing.

As far as I know, this is the only engine that has this problem. I’ve tried looking for this behavior on other game engines that I know of and sure enough, they don’t have this issue. Because of that, I find it hard to believe that this is deliberately designed behavior and not an oversight by the devs.

Maybe it’s just me being picky and this isn’t a big deal,but I feel that this is something that players can so easily encounter while playing the game on PC.

Again, thanks for the info. I hope there is another workaround for this problem.

Edit Part
I was thinking about that focus and maybe what i originally write below is indeed wrong
Maybe for game when you hold key and alt+tab
You are leaving game in state where key is pressed
And if that is the case
When you re focus game will think butt is still pressed
So you still will need to press and release key for it to register key release or key NOT being pressed

If so then solution COULD be adding condition
Window focused

Again IDK if it will work for anything maybe there is some way to use this condition to deactivate all pressed keys
For sure doable with variable

Like if space (jump) key is pressed set variable “PlayerJump” to true
Now in other event you would need
PlayerJump = True
Action simulate player jump key

And now if you use Window focused ( inverted ) condition
In action you could go with
Set PlayerJump to false

It will NOT release the key but it would stop player from jumping constantly


You can’t have trigger once in condition where you check if key is NOT pressed
So it runs every frame
Most likely that’s why it did not work

But maybe i am wrong on that i did not test it is just my assumption based on how gdevelop logic works

As for bug or not bug or engine related
You are right and wrong
It is engine related but it is not a bug
IDK if you are aware but EVERYTHING you play in gdevelop is not like other engines
You are playing inside lightweight browser
That’s why your game files can be like ldk 10 mb in size
But after export to exe or zip it is like 150+ mb

Because engine is exporting your crap with that light weight browser
AND that focus thing is browser thing
And by proxy since gdevelop uses browser to play our crap we can claim it is engine thing

But for sure it is not a bug
In same way for security reason if you have music in your game playing from starting scene from beginning of the scene
NO ONE will hear any audio unless they interact with game window
Either by clicking it with mouse or making touch on mobile

This is not gdevelop thing this is just how browser works (devs repeat it is for security reasons)
Same crap with focus