Legacy GM [SOLVED] How to make the mouse stay on 1 monitor?

TheBroman90

Member
I did not know this, because I only have one monitor. But apparently when you have multiple monitors it is possible to move the mouse outside the game to another monitor, which is something that I do not want.

How do I lock the screen and make the mouse stay inside the game?
 
M

Multimagyar

Guest
you could use the display_mouse_get_x(); display_mouse_get_y(); to get the location of the mouse. there are similar functions for getting the window position and width/height (window_get_x/y/width/height) if you want the mouse to stay inside the game you could use those to ask if the mouse is inside or outside of the game area. Then you could set the mouse position with display_mouse_set(x, y); function. With these you pretty much just have to check if the mouse is inside the box or outside then push the mouse back to the location closest to the known to be inside the box. in this case the border will be always the closest point.
I'm not quite sure if there is a specific function to ask how many and which display the mouse is on.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Using window_mouse_ functions is generally the way to go. It will not grant "perfect" mouselock since your code would still be running at some specific frequency and the mouse would be able to escape between these points of time, but combining with auto-pause and a bit of padding usually works alright.

For "perfect" mouselock you'd need system-level functionality. I made a DLL for that.
 
Top