How to lock cursor in game?

Unfortunately it’s not currently possible with the Scripting API, though I have requested this before: Feature Request: add Camera.mouseLocked to the public API