Restricting Mouse to Screen Bounds
Introduction
Some games benefit from keeping the mouse within the screen bounds. The two common scenarios for keeping the mouse within the screen bounds are:
A first person shooter uses the mouse to move around. The mouse should be invisible and not move outside of the window when the window has focus.
Real time strategy games often implement "edge scrolling" (scrolling the camera when the mouse reaches the edge of the screen).
Keeping the mouse a the center of the screen
If the mouse is invisible then the easiest way to keep the mouse in screen is to continually reset its position every frame:
Keeping the mouse bound to the window
The mouse can be bound to the window as shown in the following code:
Code obtained from http://xboxforums.create.msdn.com/forums/p/3553/18372.aspx
Last updated