Skip to content

Instantly share code, notes, and snippets.

@atward
Created April 8, 2018 05:14
Show Gist options
  • Save atward/ea1ee77e6c245b35e4082307bd2f0eda to your computer and use it in GitHub Desktop.
Save atward/ea1ee77e6c245b35e4082307bd2f0eda to your computer and use it in GitHub Desktop.
Script to allow positioning of windows based on quadrants of the current monitor
; Script to allow positioning of windows based on quadrants of the current monitor
; https://autohotkey.com/board/topic/108780-move-window-to-half-quarter-of-current-monitor/
#Backspace::
MoveIt(8)
Return
#\::
MoveIt(2)
Return
MoveIt(Q)
{
; Get the windows pos
WinGetPos,X,Y,W,H,A,,,
WinGet,M,MinMax,A
; Calculate the top center edge
CX := X + W/2
CY := Y + 20
SysGet, Count, MonitorCount
num = 1
Loop, %Count%
{
SysGet, Mon, MonitorWorkArea, %num%
if( CX >= MonLeft && CX <= MonRight && CY >= MonTop && CY <= MonBottom )
{
MW := (MonRight - MonLeft)
MH := (MonBottom - MonTop)
MHW := (MW / 2)
MHH := (MH / 2)
MMX := MonLeft + MHW
MMY := MonTop + MHH
if( M != 0 )
WinRestore,A
if( Q == 1 )
WinMove,A,,MonLeft,MMY,MHW,MHH
if( Q == 2 )
WinMove,A,,MonLeft,MMY,MW,MHH
if( Q == 3 )
WinMove,A,,MMX,MMY,MHW,MHH
if( Q == 4 )
WinMove,A,,MonLeft,MonTop,MHW,MH
if( Q == 5 )
{
if( M == 0 )
WinMaximize,A
else
WinRestore,A
}
if( Q == 6 )
WinMove,A,,MMX,MonTop,MHW,MH
if( Q == 7 )
WinMove,A,,MonLeft,MonTop,MHW,MHH
if( Q == 8 )
WinMove,A,,MonLeft,MonTop,MW,MHH
if( Q == 9 )
WinMove,A,,MMX,MonTop,MHW,MHH
; MsgBox, X: %X% Y: %Y% W: %W% H: %H% CX: %CX% CY: %CY% MonLeft: %MonLeft% MonRight: %MonRight% MonTop: %MonTop% MonBottom: %MonBottom%
return
}
num += 1
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment