ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE. Software > Post New Requests Here

IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup

(1/6) > >>

Hi there oh-guru-of-coding-snacks!   :-*

I have two monitors on my system, which I find REALLY useful (if haven't tried this setup, I REALLY recommend it!) and sometimes have the situation where I don't want the mouse going anywhere near the second monitor, e.g. when playing some full-screen games on monitor 1, the mouse will travel onto monitor 2, and make the game window inactive.

So, is it possible to put together a little proggie to make the mouse stay on the current monitor (1 or 2 or whatever the current monitor ID is) through a key-combo toggle?

Question: if it's a system setting (i.e. a mouse hook) will all programs respect the confinement rule?

Anyway, REALLY looking forward to hearing from you about this!  :)

Many thanks in advance

I would be interested in this too.  We have a set up at church where one monitor has Powerpoint Presenter running and the other feed is to a data projector showing the presentation.  Often the mouse disappears into the presentation and requires a huge amount of horizontal scrolling to get it back.  A way of limiting it to the first monitor would be good.


Carol Haynes:
I haven't got multi monitors to check but I assume that the X,Y coordinates just continue increasing/decreasing across the monitors as you move the mouse.

If this is the case it should be easy to write an AHK script using MouseGetPos and MouseMove that monitors the mouse position and if it goes outside certain boundaries it moves it back to the edge of the area.

It's too late at night here now but if noone else wants to do it I give it a stab tomorrow.

Can you confirm my first assumption is correct and if so give me the monitor size you are using where you want the mouse confined. (ie. the smallest and largest XY coordinates for the monitor,eg. my single monitor goes for X=0, Y=0 to X=1280, Y=1024)

As Carol mentioned, this is possible in AHK. But it won't work exactlly as Poolee asked for.
Notice that the mouse can be moved only after it passes from one screen to the other. It needs to pass to the other screen for it to be detected and moved back. So, it'll still make the games minimize, Poolee.
On the other hand, it's easy to do what JeffK asked for.
The following code should do it:

--- ---CoordMode,Mouse,Screen
If MouseX > %A_ScreenWidth%

[edit]the code above restricts the mouse to the primary screen. To restrict the mouse to the secondary screen (located on the right), replace '>' with '<'.[/edit]

Carol Haynes:
How about changing it to screenwidth-2 (when restricting to the primary screen) that way it should never reach the edge and so can't move to the other screen at all (+2 for the other monitor). A 2 pixel buffer shouldn't affect what you can do on the screen anyway.


[0] Message Index

[#] Next page

Go to full version