Welcome Guest.   Make a donation to an author on the site October 30, 2014, 10:20:20 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
View the new Member Awards and Badges page.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1] 2 Next   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: IDEA: Confine Mouse to Specific Monitor in Multi-monitor setup  (Read 26802 times)
Poolee
Charter Member
***
Posts: 13


View Profile Give some DonationCredits to this forum member
« on: April 09, 2006, 02:52:02 PM »

Hi there oh-guru-of-coding-snacks!   Kiss

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!  smiley

Many thanks in advance
Poolee
Logged
JeffK
Charter Member
***
Posts: 362


View Profile Give some DonationCredits to this forum member
« Reply #1 on: April 09, 2006, 07:10:30 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
Logged
Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,958



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #2 on: April 09, 2006, 07:19:27 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)
Logged

jgpaiva
Global Moderator
*****
Posts: 4,711



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #3 on: April 09, 2006, 07:30:36 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:
[copy or print]
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:39 PM by jgpaiva » Logged

Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,958



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #4 on: April 09, 2006, 07:37:26 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.
Logged

jgpaiva
Global Moderator
*****
Posts: 4,711



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #5 on: April 09, 2006, 07:43:26 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... Sad
Logged

Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,958



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #6 on: April 10, 2006, 03:35:14 AM »

Wink - 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?
Logged

skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #7 on: April 10, 2006, 07:36:40 AM »

 smiley 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.

[copy or print]
XXXX
XXXX
XXXX
    XXXX
    XXXX
    XXXX

Skrommel
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #8 on: April 10, 2006, 07:40:55 AM »

 smiley 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
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #9 on: April 10, 2006, 08:13:41 AM »

 smiley Updated ConfineMouse to v1.1.

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

Skrommel
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
Poolee
Charter Member
***
Posts: 13


View Profile Give some DonationCredits to this forum member
« Reply #10 on: April 10, 2006, 06:36:02 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
Logged
JeffK
Charter Member
***
Posts: 362


View Profile Give some DonationCredits to this forum member
« Reply #11 on: April 11, 2006, 03:47:30 AM »

Haven't tried them yet but thanks for the hints above.  I'll give them a go.

Jeff
Logged
skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #12 on: April 11, 2006, 03:08:39 PM »

 embarassed Sorry, the tooltip was for debugging. Download the one I just uploaded.

Skrommel
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #13 on: April 11, 2006, 04:17:21 PM »

 smiley Uploaded ConfineMouse v1.2. Added hotkey for disabling.

Skrommel
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
skywalka
Member
**
Posts: 253


View Profile Give some DonationCredits to this forum member
« Reply #14 on: May 10, 2006, 04:05:28 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.
Logged
skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #15 on: May 11, 2006, 08:37:35 AM »

 smiley 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.

[copy or print]
XXXX
XXXX
XXXX
XXXXXXXX
    XXXX
    XXXX
    XXXX

Skrommel
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
jgpaiva
Global Moderator
*****
Posts: 4,711



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #16 on: May 11, 2006, 09:13:31 AM »

smiley 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 Wink
Logged

skywalka
Member
**
Posts: 253


View Profile Give some DonationCredits to this forum member
« Reply #17 on: May 11, 2006, 09:33:58 AM »

 Grin I never even knew it was possible to rearrange the monitors like that. embarassed  I've moved the extra monitor to the left which greatly minimises the problems I was having with scrollbars.

Thanx.
Logged
darklight_tr
Charter Member
***
Posts: 39



View Profile Give some DonationCredits to this forum member
« Reply #18 on: August 15, 2007, 12:29:36 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:10 AM by darklight_tr » Logged
snouffelaire
Member
**
Posts: 1

View Profile Give some DonationCredits to this forum member
« Reply #19 on: October 23, 2009, 04:06:44 PM »

Hello,
I just wrote a little app for that: http://ddmm.sourceforge.net/ (it's open source)
Logged
mouser
First Author
Administrator
*****
Posts: 33,610



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #20 on: October 23, 2009, 06:05:36 PM »

Nice work snouffelaire, and welcome to the site  thumbs up
Logged
lanux128
Global Moderator
*****
Posts: 6,119



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #21 on: October 23, 2009, 10:54:44 PM »

cool! this is quite an useful program. thanks snouffelaire. smiley
Logged

BaNDiToS
Participant
*
Posts: 2


View Profile Give some DonationCredits to this forum member
« Reply #22 on: October 29, 2009, 03:21:27 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.

Formatted for AutoIt with the GeSHI Syntax Highlighter [copy or print]
  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
Logged
mouser
First Author
Administrator
*****
Posts: 33,610



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #23 on: October 29, 2009, 03:58:20 PM »

Welcome to the site BaNDiToS  Thmbsup
Are we right in assuming you wrote this code?
Logged
BaNDiToS
Participant
*
Posts: 2


View Profile Give some DonationCredits to this forum member
« Reply #24 on: October 29, 2009, 04:07:15 PM »

Thanks for welcome. smiley

Yes, I wrote the code. If something isn't clear, I can explain it.
Logged
Pages: [1] 2 Next   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.115s | Server load: 0.02 ]