Endless mouse

Share your favorite FastKeys commands
User avatar
Tom
Posts: 657
Joined: Nov 24th, ’15, 23:39

Post by Tom » Mar 12th, ’19, 20:36

You can use a A_ScreenWidth variable (width of primary monitor) instead of fixed numbers.
TokyoMike
Posts: 29
Joined: May 10th, ’18, 07:01

Post by TokyoMike » Mar 19th, ’19, 10:35

Tom wrote:
Mar 12th, ’19, 20:36
You can use a A_ScreenWidth variable (width of primary monitor) instead of fixed numbers.
Thank you. This worked on my giant monitor but when I switched back to my laptop it didn't The variable wouldn't correctly sense the right edge of the screen.

I put the numeric values in again for the small screen and things worked again. Is there any chance the A_ScreenWidth variable somehow "remembered" my large screen (like 3840) even after switching to the laptop screen? This is after reboots and several start/stops of Fastkeys. I am curious if something might be hard coded.
User avatar
Tom
Posts: 657
Joined: Nov 24th, ’15, 23:39

Post by Tom » Mar 21st, ’19, 20:35

Do you use multiple monitors? A_ScreenWidth is a system variable and it's value is always a width of your primary monitor.

What do you get if you put this line to the script?

Code: Select all

Msgbox % A_ScreenWidth
TokyoMike
Posts: 29
Joined: May 10th, ’18, 07:01

Post by TokyoMike » Mar 23rd, ’19, 02:23

Tom wrote:
Mar 21st, ’19, 20:35
Do you use multiple monitors? A_ScreenWidth is a system variable and it's value is always a width of your primary monitor.

What do you get if you put this line to the script?

Code: Select all

Msgbox % A_ScreenWidth
Ah - I see, maybe. At the office when I start my laptop I have the laptop open and it is connected to my monitor. At that moment there are 2 screens. Then I close the laptop lid and work from my monitor. So there is a change.

Now - that being said.

Today, from home (no external monitor) I added the message box as you suggested and it shows 1920. BUT - for some reason, the script is not working.

Am I doing the "math" wrong in the script?

Code: Select all

#Persistent
CoordMode, Mouse, Screen

SetTimer, ClosePopup, 500

Msgbox % A_ScreenWidth

ClosePopup:
MouseGetPos, xpos, ypos
IfGreater, xpos, %A_ScreenWidth%-2 ; my screen with is 1920 pixels
	MouseMove, -%A_ScreenWidth%-2, 0, 0, R
IfLess, xpos, 1
	MouseMove, %A_ScreenWidth%-2, 0, 0, R
;IfLess, ypos, 1
;	MouseMove, 0, 1078, 0, R
return
Thank you for your help.
User avatar
Tom
Posts: 657
Joined: Nov 24th, ’15, 23:39

Post by Tom » Mar 23rd, ’19, 21:49

This should work.

Code: Select all

CoordMode, Mouse, Screen
SetTimer, ClosePopup, 200

ClosePopup:
MouseGetPos, xpos, ypos
if (xpos > A_ScreenWidth-2)
	MouseMove, -A_ScreenWidth-2, 0, 0, R
if (xpos < 1)
	MouseMove, A_ScreenWidth-2, 0, 0, R
return
TokyoMike
Posts: 29
Joined: May 10th, ’18, 07:01

Post by TokyoMike » Mar 24th, ’19, 01:04

Tom wrote:
Mar 23rd, ’19, 21:49
This should work.

Code: Select all

CoordMode, Mouse, Screen
SetTimer, ClosePopup, 200

ClosePopup:
MouseGetPos, xpos, ypos
if (xpos > A_ScreenWidth-2)
	MouseMove, -A_ScreenWidth-2, 0, 0, R
if (xpos < 1)
	MouseMove, A_ScreenWidth-2, 0, 0, R
return
Thanks! This works great on my laptop - I will test with my giant monitor at the office on Monday.

Cheers!
TokyoMike
Posts: 29
Joined: May 10th, ’18, 07:01

Post by TokyoMike » Mar 25th, ’19, 08:30

TokyoMike wrote:
Mar 24th, ’19, 01:04
Thanks! This works great on my laptop - I will test with my giant monitor at the office on Monday.
Works great - the value adjusts properly. I suspect your logic is better than the original.

Thanks!
TokyoMike
Posts: 29
Joined: May 10th, ’18, 07:01

Post by TokyoMike » Apr 22nd, ’21, 04:47

Would it be possible to extend this to work with two monitors? The expectation would be to have the cursor wrap from the left of monitor to the right of the next monitor.

If (monitor1) and xpos = extreme left then movecursor to monitor2 and xpos extreme right and so on.
User avatar
Tom
Posts: 657
Joined: Nov 24th, ’15, 23:39

Post by Tom » Apr 23rd, ’21, 17:41

You could use the following code to get the far left and far right coordinates of all monitors.

Code: Select all

SysGet, monCount, 80
MonLeft:=MonRight:=0
Loop, % monCount 
{
    i := A_Index
    SysGet, mon%i%, Monitor, %i%
    MonLeft := (mon%i%Left<MonLeft) ? mon%i%Left : MonLeft
    MonRight := (mon%i%Right>MonRight) ? mon%i%Right : MonRight
}
TokyoMike
Posts: 29
Joined: May 10th, ’18, 07:01

Post by TokyoMike » Aug 19th, ’21, 05:24

Apologies for resurecting an old thread. I recently ditched a commercial piece of software that does this.

The following code works, almost...

I have two monitors with different resolutions. The YPOS doesn't work on my second monitor because its resolution is LESS than the resolution of the main monitor. While YPOS<2 works from TOP wrapping to BOTTOM, the BOTTOM does not work on my lower resolution monitor. It seems that A_Screenheight is not getting the Y resolution for the "current monitor your cursor is on" it is getting the overall largest value. Since my second monitor is smaller, the YPOS -2 never gets achieved, so on this monitor wrapping from BOTTOM to TOP does not work.

REQUEST: is there a way to change this logic to determine WHICH monitor the cursor is on and to calculate the max Y value for that monitor and if the cursor is moved beyond that it is wrapped to the TOP of that monitor.

Thank you for any help you can provide.

Code: Select all

CoordMode, Mouse, Screen
SetTimer, ClosePopup, 200

SysGet, monCount, 80
MonLeft:=MonRight:=0
Loop, % monCount 
{
    i := A_Index
    SysGet, mon%i%, Monitor, %i%
    MonLeft := (mon%i%Left<MonLeft) ? mon%i%Left : MonLeft
    MonRight := (mon%i%Right>MonRight) ? mon%i%Right : MonRight
}
ClosePopup:
MouseGetPos, xpos, ypos
if (xpos > MonRight-2)
	MouseMove, MonLeft-(MonLeft-2), ypos, 0
if (xpos < MonLeft-(MonLeft-2))
	MouseMove, MonRight-2, ypos, 0

if (ypos > A_ScreenHeight-2)
	MouseMove, xpos, 2, 0
if (ypos < 2)
	MouseMove, xpos, A_ScreenHeight-2, 0
return
Post Reply