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


#1

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)?


#2

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


#3

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?


#4

Yeah, that’s what I want to do.


#5

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 (https://developer.playcanvas.com/en/api/pc.Mouse.html#isPointerLocked) every frame and when it is unlocked, (last frame was locked, current frame unlocked), show the menu UI.


#6

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