Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Stop cursor at screen edge? Dual monitor help


  • Please log in to reply
29 replies to this topic
MikeJ
  • Guests
  • Last active:
  • Joined: --
I have a dual monitor setup with the second monitor to my right. I have a problem "overshooting" to the other monitor when going for my scrollbar.

My desire, when touching the farthest right side, is to
1)
have the mouse stop at X configurable amount of pixels to the right (1440 in my case) and then snap back left X configurable pixels (about 5 -10) so that I end up approximately on the scrollbar.
2)
The above should be disabled back to normal "pass-thru" operation by holding the "ctrl" button down while moving the mouse.
3)
No gui necessary, in fact I`d like to easily add the code to my existing scripts.

From what I can tell by searching google for 2 hours, is that there is a great desire for something like this , especially in the gaming community, but all similiar programs fall short for me in some way. "ConfineMouse" from "Skrommels One Hour Software" is writen with AHK and comes very close, but has problems. Unfortunately it still allows the cursor to be moved about 20 pixels inside the second monitor, rendering it pointless. Also, as with other "cursor lock" programs, the pass-thru is either off or on at all times. I would prefer to always lock the designated side, but have the "temporary" pass-thru by holding down a key only.

This seems possible, perhaps quite easy, but definately beyond my skill.

Thanks for any input.

MikeJ
  • Guests
  • Last active:
  • Joined: --
I think holding down the designated control button need only bypass the entire script, that part of it should be straight forward enough? Or no?

MikeJ
  • Guests
  • Last active:
  • Joined: --
OK the following is taken and modified from Skrommel's "ConfineMouse" and now works pretty well for containing the cursor to a few pixels from the edge. However I still can't figure out how to disable it while holding down a key, i.e. control or mbutton. I can make it work only after pressing a button, but not the other way around. I feel I need a "while" somehow, but I cant get it to work with a key. Any help just on that part? I`m really trying!

CoordMode,Mouse,Screen
SysGet,monitor,Monitor,%activemonitor%
Loop
 {
 Sleep,100
 MouseGetPos,x,y
 If (x>monitorRight)
   MouseMove,1427,%y%,0
 }
return


TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Please post code **edit you beat me to it ;)

I also have a dual monitor setup like this.

1st off specifically for scrolling, you may be able to use these SendMessage commands.

; Standard windows scroll message.
; May not work in non standard windows (eg. FireFox)
; Page Up to scoll up.
; Page Down to scroll down.

PgUp::
ControlGetFocus, control, A
 SendMessage, 0x115, 0, 0, %control%, A 

Return

PgDn::
ControlGetFocus, control, A
 SendMessage, 0x115, 1, 0, %control%, A 

Return

Next, if you cannot use those and you still need to control the max position of the mouse you could either use:

- Get the size of the monitor with A_ScreenWidth & A_ScreenHeight.
- Get the size of the control or window with the scroll bar and send mouse to the appropriate coords.
- Dont forget to use CoordMode, Mouse and appropriate 2nd parameter.

Hope this is what your after.

Posted Image

don't duplicate, iterate!


MikeJ
  • Guests
  • Last active:
  • Joined: --
No all I`m needing should be very simple: i.e. hold down the mbutton to disable the above script, thereby letting the mouse enter into screen #2.

NOT that following is functional by any means, but as an example it would be something along the lines of:

WHILE mbutton is held down
{do nothing, let the mouse cursor onto screen #2}

ELSE
{Loop
 {
 Sleep,100
 MouseGetPos,x,y
 If (x>monitorRight)
   MouseMove,1427,%y%,0
 }}

jeez i hope that makes sense. Sorry I`m very new.

MikeJ
  • Guests
  • Last active:
  • Joined: --
Something like below could also work out, if holding a button doesn't ...

Middle click mouse: causes above script to stop looping for say 5 seconds, just long enough to move the cursor to monitor # 2

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Its ok I did not read closely enough..

Test this out (untested ofcourse)..
Loop,
  {
   MouseGetPos, X, Y
	If  {X>monitorRight}
		{
		MouseMove, 1427, %Y%,0
		}
		GetKeyState, mbPressed, MButton, P
			If mbPressed = D
				Break
			Else
				Continue
  }

It should stop the locking mouse when Mbutton is pressed but not held. To get that just create another loop after that sends back to this loop if MButton is up or U ;).. There is a shorter way I think though.. Anyway this should work.

Posted Image

don't duplicate, iterate!


MikeJ
  • Guests
  • Last active:
  • Joined: --
WOW I figured it out. (posted here for other newbs) Code "cleanup" tips would still be welcome!

CoordMode,Mouse,Screen
SysGet,monitor,Monitor,%activemonitor%
Loop
if not GetKeyState("MButton") ; Do the following only if the middle mouse button is NOT held down
 {
 Sleep,100
 MouseGetPos,x,y
 If (x>monitorRight) ; if mouse hits edge of right screen
 MouseMove,1435,%y%,0 ; moves mouse back to 5 pixels from edge, my resolution happens to be 1440 x 900
 }
return


MikeJ
  • Guests
  • Last active:
  • Joined: --
Sorry I ran over your post. I was all happy I did it. - Thanks for yours, I`ll see if anything can be incorporated to mine

MikeJ
  • Guests
  • Last active:
  • Joined: --
Nevermind - mine doesnt work after all. When I let go of the mbutton, it ssaps all the way back to the screen instead of letting me stay on #2. I`ll try playing with yours, TLM.

MikeJ
  • Guests
  • Last active:
  • Joined: --
This is getting too complicated - I just realized that it must only work while the mouse is on screen #1. The way both scripts are, while on screen #2 its always going to snap back to monitor #1.

This stinks - i`ll never figure out that one! I would not only have to cancel the loop by a button, but also cancel the loop when the cursor is over 1441 pixels. Thats just beyond my small brain power.

You'd think someone would have already thought of this.

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006

This is getting too complicated - I just realized that it must only work while the mouse is on screen #1. The way both scripts are, while on screen #2 its always going to snap back to monitor #1.

This stinks - i`ll never figure out that one! I would not only have to cancel the loop by a button, but also cancel the loop when the cursor is over 1441 pixels. Thats just beyond my small brain power.

You'd think someone would have already thought of this.

I think you just need another if over X to disable the initial action ;)... For instance
.....
 If (x>monitorRight)
...
Else If (x<monitorRight)
...

Keep at it, I'm sure you'l get it in no time..

Posted Image

don't duplicate, iterate!


MikeJ
  • Guests
  • Last active:
  • Joined: --
This is the best I can come up with. It does absolutely nothing.
CoordMode,Mouse,Screen
SysGet, Mon1, Monitor, 1
SysGet, Mon2, Monitor, 2


Loop 
sleep,100
MouseGetPos,x,y
    if not(x>Mon2Left)
            {
                   if not GetKeyState("MButton")
                         {
                         If (x>monitorRight)
                         MouseMove,1435,%y%,0 
		         }
            }


MikeJ
  • Guests
  • Last active:
  • Joined: --
I`ve spent like 6 hours on something that should take 10 min for someone who knows what their doing. Thats just wrong.

purloinedheart
  • Members
  • 538 posts
  • Last active: Sep 22 2014 09:35 PM
  • Joined: 04 Apr 2008
Not tested. Should help you get started.

CoordMode Mouse, Screen
SetBatchLines -1
Side := 1440
SetTimer Monitor, 0

Monitor:
MouseGetPos X, Y
if X > %Side%
 {
  BlockInput Mouse
  MouseMove % Side -8,% Y
  Blockinput off
 }
return

~MButton::
MouseGetPos X
 if X<%Side%
  {
   SetTimer Monitor, Off
   KeyWait MButton
   MouseGetPos X
   if X>%Side%
    SetTimer Monitor, off
   else
    SetTimer Monitor, 0
  }
else
 SetTimer Monitor, 0
return