[SOLVED] How to disable "Hit Esc to show your cursor"

I am creating a FPS game and when you click the “Start” button on my menu screen it enables the pointer lock and a message of “Hit Esc to show your cursor” comes up at the top of the screen (similar to “Hit Esc to exit full screen mode” when watching a video). And then, when I want to get to the start menu again, I have to hit Esc twice, once to disable the cursor lock, and twice to actually pull up the menu. However, the first Esc should be unnecessary because I already have a line that disables the cursor lock when you hit Esc and pulls up the start menu at the same time.

if (app.keyboard.wasPressed(pc.KEY_ESCAPE)) {
        this.app.mouse.disablePointerLock();
        userMenu.enabled = true;
        ui.enabled = false;
    }

What can I do to stop this default message from appearing (I’m pretty sure it has something to do with my issue)?

You can’t, it’s a browser feature.

1 Like

Is the actual problem that you just want to be able to press Esc once to unlock the mouse and bring up the menu at the same time?

1 Like

Yeah, that’s what I want to do.

My guess is that the browser consumes the Escape key event when unlocking the cursor so PlayCanvas never gets the event to react to.

I would either use a different key (M for example) or have some code that checks the state of the cursor lock (Mouse | PlayCanvas API Reference) every frame and when it is unlocked, (last frame was locked, current frame unlocked), show the menu UI.

2 Likes

I tried the second solution you provided, and it worked just fine! Thanks!

Hello, sorry to reup an old subject but do you know how Stadia is doing to disable the escape to show your cursor message ? Thanks a lot !

Is that in all browsers? Or just Chrome? If just Chrome, my guess is that own both Stadia and Chrome so they can cheat :sweat_smile: