My goal is to provide a hotkey that moves the mouse to the center of the monitor for each monitor in a multi-monitor config. For example:
Alt+Ctrl+1 ==> move mouse to monitor 1
Alt+Ctrl+2 ==> move mouse to monitor 2
Alt+Ctrl+3 ==> move mouse to monitor 3
Alt+Ctrl+4 ==> move mouse to monitor 4
Alt+Ctrl+5 ==> move mouse to monitor 5
Alt+Ctrl+6 ==> move mouse to monitor 6
Alt+Ctrl+7 ==> move mouse to monitor 7
Alt+Ctrl+8 ==> move mouse to monitor 8
Alt+Ctrl+9 ==> move mouse to monitor 9
Alt+Ctrl+0 ==> move mouse to primary monitor regardless of its number
Here's a script that attempts to do it:
Code: Select all
#Warn,UseUnsetLocal
#NoEnv
#SingleInstance Force
SetBatchLines,-1
HotkeyModifiers:="!^" ; Alt+Ctrl - these are the modifier keys for the number keys (0-9) - change them to whatever you want
NumModifiers:=StrLen(HotkeyModifiers) ; get number of modifier keys
MoveToX:={} ; array for mouse-move X coordinates
MoveToY:={} ; array for mouse-move Y coordinates
CoordMode,Mouse,Screen ; default, but just to be sure
SysGet,NumMons,MonitorCount ; get number of monitors
Hotkey,%HotkeyModifiers%0,MoveMousePrimary,On ; define Modifiers+0 hotkey to move mouse to Primary monitor regardless of its monitor number
Loop,%NumMons% ; process all monitors
{
MonNum:=A_Index
SysGet,Coordinates%MonNum%,Monitor,%MonNum% ; get coordinates for this monitor
Left:=Coordinates%MonNum%Left
Right:=Coordinates%MonNum%Right
Top:=Coordinates%MonNum%Top
Bottom:=Coordinates%MonNum%Bottom
MoveX:=Floor(0.5*(Right-Left)) ; center
MoveY:=Floor(0.5*(Bottom-Top)) ; center
MoveToX[MonNum]:=Left+MoveX ; store mouse-move X coordinate for this monitor
MoveToY[MonNum]:=Top+MoveY ; store mouse-move Y coordinate for this monitor
Hotkey,%HotkeyModifiers%%MonNum%,MoveMouseMon,On ; define Modifiers+N hotkey
}
Return
MoveMouseMon:
MonNum:=SubStr(A_ThisHotkey,NumModifiers+1,1) ; monitor number is after the modifiers
X:=MoveToX[MonNum] ; retrieve horizontal mouse-move coordinate
Y:=MoveToY[MonNum] ; retrieve vertical mouse-move coordinate
MouseMove,%X%,%Y% ; move it!
Return
MoveMousePrimary:
SysGet,PrimaryMonNum,MonitorPrimary ; get number of Primary monitor
X:=MoveToX[PrimaryMonNum] ; retrieve horizontal mouse-move coordinate
Y:=MoveToY[PrimaryMonNum] ; retrieve vertical mouse-move coordinate
MouseMove,%X%,%Y% ; move it!
Return
Here are two monitor configs where it fails:
Seems to me that what's needed is a CoordMode option that is relative to a specific monitor number. But, of course, the only CoordMode options are Client, Screen, and Window (the latter being synonymous with Relative, but it's relative to the active window, not to the whole monitor, so not what's needed).
I looked at all the (Numeric) values of the SysGet options, but nothing there seems to be the ticket.
Anyone have a solution for this? Thanks much, Joe