Check the properties "IsInputCaptured" and "IsMouseOverGui" of the Screen class.
There's a big block of documentation above each of those methods, but normally you'd do something like this:
- By default, you use IsMouseOverGui to decide if your game of the GUI should handle mouse move events
- If a mouse button is pressed down while the mouse was in the game area, do not send any input to the GUI. All input belongs to the game, even if the mouse goes over the GUI, until all mouse buttons have been released again.
- If a mouse button is pressed down while the mouse was over the GUI, it sets IsInputCaptured to true and all input belongs to the GUI, even if the mouse goes over the game, until all mouse buttons have been released again
That way, the player can for example draw a selection rectangle around some units and there won't be weird things happening when he crosses a GUI control.