Mouse to center of the screen but then unlock after in-game menu opens

Hello, I have come across a problem with my mouse movement. I am able to move around perfectly in first person, the thing is that the mouse cursor moves around the screen, and doesn’t stay “centered”. Whenever I press “tab” to open the in-game menu, the mouse cursor is on the corners of the screen and it is not in the center. I was wondering if there was a way to keep the mouse cursor “centered” until I open the menu, and when I open the menu, for it to be “unlocked” like it was before so you can use it to click the menu settings.
Thank you,