The fine details about how to do this are difficult without knowing what type of game you’re making, or the language it’s written in. Still, assuming you’re talking about a browser game, a good place to start would be looking at the Pointer Lock API. This probably won’t be an easy drop-in solution though; you need to ask permission first, and might need to implement your own fake mouse pointer.