Not too sure how to ask this, I'll try my best.
Currently, I'm working on a First-Person Controller. I'm adding functionality for a pause menu so that when you press escape, it will open the pause menu, unlock the cursor, and make it visible. If you press escape again, while the pause menu is open, it will do the opposite: hide the cursor and lock it again.
The problem I'm running into is that Unity already kind of does this. It doesn't matter if you're in the editor or if your game is built: whenever you press escape, it will unlock the cursor and show it, so you can exit the game (in a built application) or get out of play mode (in the editor).
I'm 99% sure this is Unity's default functionality. I have looked in Unity itself and haven't found a way to turn it off, and I have also looked online. Any help would be greatly appreciated.