topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 7:17 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup  (Read 44274 times)

Poolee

  • Charter Member
  • Joined in 2006
  • ***
  • default avatar
  • Posts: 13
    • View Profile
    • Donate to Member
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
Poolee

JeffK

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 363
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #1 on: April 09, 2006, 07:10 PM »
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.

Jeff

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 8,066
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #2 on: April 09, 2006, 07:19 PM »
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)

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #3 on: April 09, 2006, 07:30 PM »
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
loop
{
Mousegetpos,MouseX,MouseY
If MouseX > %A_ScreenWidth%
  MouseMove,%A_ScreenWidth%,%MouseY%,0
}

[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]
« Last Edit: April 09, 2006, 07:32 PM by jgpaiva »

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 8,066
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #4 on: April 09, 2006, 07:37 PM »
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.

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #5 on: April 09, 2006, 07:43 PM »
I'm afraid that doesn't work too, if you move the mouse fast enough, you can get to almost 1/4th of the other screen... :(

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 8,066
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #6 on: April 10, 2006, 03:35 AM »
;) - at least if you get to 1/4 of the way across the other screen it should snap straight back.

I wonder if it is possible in AHK to make a boundary box?

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 933
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #7 on: April 10, 2006, 07:36 AM »
 :) What you could try is to move your monitors around in the Desktop properties' Settings window, placing them side by side, the one above the other. If they are barely touching, the intersection is the only place where your mouse can travel from the one monitor to the other.

XXXX
XXXX
XXXX
    XXXX
    XXXX
    XXXX

Skrommel

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 933
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #8 on: April 10, 2006, 07:40 AM »
 :) Or if you don't need to absolutely lock the mouse to one monitor, try this, it just moves it back.

ConfineMouse - Confine the mouse to one monitor.

Features:
- DoubleClick the tray icon to Disable/Enable.

You'll find the downloads and more info at 1 Hour Software by Skrommel.

Skrommel

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 933
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #9 on: April 10, 2006, 08:13 AM »
 :) Updated ConfineMouse to v1.1.

Made it change to the monitor chosen in the settings without a restart.

Skrommel

Poolee

  • Charter Member
  • Joined in 2006
  • ***
  • default avatar
  • Posts: 13
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #10 on: April 10, 2006, 06:36 PM »
Wow, that's awesome, and works really well!   :Thmbsup:

Can you please add a setting to turn the tooltip on and off? 

Also, I got caught a couple of times with the mouse on the second monitor and couldn't get it back to the first, so had to tab, tab, cursor, tab, cursor until I got the icon in the systray then right-mouse click on the keyboard and disable the icon...  so is there any chance of a key combo to toggle it on and off?

One last thing... if I click as I move the mouse off the edge, the window in that monitor becomes de-activated... is there a way to suppress clicks outside the monitor's boundary?

Thanks for the awesome work!!

Poolee

JeffK

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 363
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #11 on: April 11, 2006, 03:47 AM »
Haven't tried them yet but thanks for the hints above.  I'll give them a go.

Jeff

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 933
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #12 on: April 11, 2006, 03:08 PM »
 :-[ Sorry, the tooltip was for debugging. Download the one I just uploaded.

Skrommel

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 933
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #13 on: April 11, 2006, 04:17 PM »
 :) Uploaded ConfineMouse v1.2. Added hotkey for disabling.

Skrommel

skywalka

  • Member
  • Joined in 2005
  • **
  • Posts: 254
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #14 on: May 10, 2006, 04:05 AM »
Would it be possible to stop the cursor leaving the 1st desktop at all?  At the moment it encroaches on the "extended" monitor & has to be brought back (though, not very much).  Can you force ConfineMouse's functionality to act as though there was no second monitor at all.

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 933
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #15 on: May 11, 2006, 08:37 AM »
 :) The only way I've found for this is to move the second monitor so it barely touches the first one in the Desplay settings.

XXXX
XXXX
XXXX
XXXXXXXX
    XXXX
    XXXX
    XXXX

Skrommel

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #16 on: May 11, 2006, 09:13 AM »
:) The only way I've found for this is to move the second monitor so it barely touches the first one in the Desplay settings.
This might be the solution, it's definitelly worth trying. It has a very interesting effect with the mouser positioning. Just test it, you'll be amazed at the place your mouse comes up ;)

skywalka

  • Member
  • Joined in 2005
  • **
  • Posts: 254
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #17 on: May 11, 2006, 09:33 AM »
 ;D I never even knew it was possible to rearrange the monitors like that. :-[  I've moved the extra monitor to the left which greatly minimises the problems I was having with scrollbars.

Thanx.

darklight_tr

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 39
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #18 on: August 15, 2007, 12:29 AM »
Love the program, but I have one suggestion.  Could you allow the hotkey to toggle the confinement on and off instead of just turning the confinement off?

Thanks!
« Last Edit: August 15, 2007, 12:45 AM by darklight_tr »

snouffelaire

  • Member
  • Joined in 2009
  • **
  • default avatar
  • Posts: 1
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #19 on: October 23, 2009, 04:06 PM »
Hello,
I just wrote a little app for that: http://ddmm.sourceforge.net/ (it's open source)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #20 on: October 23, 2009, 06:05 PM »
Nice work snouffelaire, and welcome to the site  :up:

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #21 on: October 23, 2009, 10:54 PM »
cool! this is quite an useful program. thanks snouffelaire. :)

BaNDiToS

  • Participant
  • Joined in 2009
  • *
  • Posts: 2
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #22 on: October 29, 2009, 03:21 PM »
This code is what probably everybody in this thread is looking for and its a pure AHK solution without .NET-Frameworks. Just start and hit Win+C to enable / disable.

Code: AutoIt [Select]
  1. #SingleInstance,Force
  2. #NoEnv
  3.  
  4. ; Mouse Rectangle Lock / Release
  5. #c::
  6.         If IsActive = True
  7.         {
  8.                 SetTimer, KeepLock, Off
  9.                 DllCall("ClipCursor", UInt, 0)
  10.                 IsActive = False
  11.         } else {
  12.                 VarSetCapacity(Rect, 16)                        ; Define var size
  13.                 NumPut(0, Rect, 0)                                      ; Left
  14.                 NumPut(0, Rect, 4)                                      ; Top
  15.                 NumPut(1600, Rect, 8)                           ; Right
  16.                 NumPut(1200, Rect, 12)                          ; Bottom
  17.                 DllCall("ClipCursor", UInt, &Rect)
  18.                 SetTimer, KeepLock, 50
  19.                 ActiveOld := WinActive("A")
  20.                 IsActive = True
  21.         }
  22.  
  23. KeepLock:
  24.         Active := WinActive("A")
  25.         If Active <> %ActiveOld%
  26.         {
  27.                 ActiveOld := Active
  28.                 DllCall("ClipCursor", UInt, &Rect)
  29.         }

Bye

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #23 on: October 29, 2009, 03:58 PM »
Welcome to the site BaNDiToS  :Thmbsup:
Are we right in assuming you wrote this code?

BaNDiToS

  • Participant
  • Joined in 2009
  • *
  • Posts: 2
    • View Profile
    • Donate to Member
Re: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup
« Reply #24 on: October 29, 2009, 04:07 PM »
Thanks for welcome. :)

Yes, I wrote the code. If something isn't clear, I can explain it.