Click window to toggle programs across monitors with AutoHotkey

toggle programs across monitorsToggle programs across monitors with AutoHotkey

Do you work with multiple monitors?  I have an awesome AutoHotkey script which allows me to simply hold down Alt and mouse-click on a program and it will “throw” it to the other monitor!.


Toggle programs across monitors with AutoHotkey

Here is the AutoHotkey Script to toggle programs across monitors

; Original post from rodfell Oct 2007 
;***********adjust next two lines to the monitors you wish to toggle between******************* 
SysGet, Mon1, Monitor, 1 ; Grab monitor number 1 create a Mon1 var
sysGet, Mon2, Monitor, 2 ; Grab monitor number 2 create a Mon2 var
;make sure you place the two above monitor lines at top of script
;************************Toggle between monitors*******************************. 
#SingleInstance, Force
#NoTrayIcon ;comment out if you want to have icon present
!RButton:: ;Alt+right mouse click= Throw window clicked on to other window
wingetpos,x1,y1,w1,h1,ahk_id %windowundermouse%
winget,winstate,minmax,ahk_id %windowundermouse%
m1:=(x1+w1/2>mon1left) and (x1+w1/2<mon1right) and (y1+h1/2>mon1top) and (y1+h1/2<mon1bottom) ? 1:2 ;works out if centre of window is on monitor 1 (m1=1) or monitor 2 (m1=2)
m2:=m1=1 ? 2:1 ;m2 is the monitor the window will be moved to
ratiox:=abs(mon%m1%right-mon%m1%left)-w1<5 ? 0:abs((x1-mon%m1%left)/(abs(mon%m1%right-mon%m1%left)-w1)) ;where the window fits on x axis
ratioy:=abs(mon%m1%bottom-mon%m1%top)-h1<5 ? 0:abs((y1-mon%m1%top)/(abs(mon%m1%bottom-mon%m1%top)-h1)) ;where the window fits on y axis
x2:=mon%m2%left+ratiox*(abs(mon%m2%right-mon%m2%left)-w1) ;where the window will fit on x axis in normal situation
w2:=w1 , h2:=h1 ;width and height will stay the same when moving unless reason not to lower in script

;if x axis takes up whole axis OR won't fit on new screen
if abs(mon%m1%right-mon%m1%left)-w1<5 or abs(mon%m2%right-mon%m2%left-w1)<5
 x2:=mon%m2%left , w2:=abs(mon%m2%right-mon%m2%left)
if abs(mon%m1%bottom-mon%m1%top)-h1<5 or abs(mon%m2%bottom-mon%m2%top)-h1<5
 y2:=mon%m2%top , h2:=abs(mon%m2%bottom-mon%m2%top)
if winstate { ;move maximized window
 winrestore,ahk_id %windowundermouse%
 winmove,ahk_id %windowundermouse%,,mon%m2%left,mon%m2%top
 winmaximize,ahk_id %windowundermouse%
else {
 winmove,ahk_id %windowundermouse%,,x2,y2,w2,h2 ;move non-maximized window

Being able to toggle programs across monitors is an amazing thing!

Comments are closed.