The condition "Escape key pressed" not detected by GDevelop when the cursor is locked

Hello, I think I found an issue with the MousePointerLock extension, or GDevelop itself, not sure.

The situation is very simple. Basically, I have a menu that opens when pressing the Escape key. This menu is on the UI layer so I just do this:

condition => Escape key is pressed
action => Show layer named “UI”

condition => (INVERTED) Escape key is pressed
action => Hide layer named “UI”

Very simple.

It also toggles a global boolean variable named “isPaused”. So, if the UI layer is shown, then “isPaused” is set to true, otherwise it is set to false. This way, I can lock the pointer, or exit the pointer lock:

Unfortunately, when pressing the Escape key, it automatically exists the pointer lock. As a consequence, I have to click twice on the Escape key to open my menu. It is because GDevelop doesn’t detect the Escape key being pressed the first time (which I verified using debug logs in the console).

I think it’s a default behaviour from the desktop platforms, as well as the web browsers, that captures the event of this key being pressed, and that they don’t propagate this to GDevelop. They would capture the event and wouldn’t tell GDevelop about it until the pointer is unlocked, see what I mean?

When I hold the Escape key, it first unlocks the pointer, and then, after like 0.5 seconds something like that, it finally opens the menu.

Soooo, do you have an other explanation, is it a glitch? Is there an alternative ? because I want to lock the pointer when the player is playing, but unlock it when they player pressed “Escape”, as well as open a menu.

This version of GDevelop is: 5.2.169 (editor full version: 5.2.169-ca220d8fe5420697fc597eb6bb201f2250cf937e, core version: 4.0.99-0-release)

Below, I prepared a simpler project to demonstrate the issue. In this example, start the preview and press K. This will lock the pointer. By default, the game is “paused” (so the player at the center of the screen cannot move). Press Escape again to see the problem in action (it will not resume the game, but unlock the pointer). Hold the key for around 500ms to finally trigger the event in the events sheet.