I want the cursor in the 3d shooter not to detach from the game when pressing esc

I want the cursor in the 3d shooter not to detach from the game when pressing esc - how to do this - I know that there is such a code for tab (so that the focus does not switch to other parts of the browser)

document.addEventListener(‘keydown’, function(event) {
if (event.key === ‘Tab’ || event.keyCode === 9) {
event.preventDefault();
}
});

is there something similar for esc? so that I can use this button for my game