Skip to content

Instantly share code, notes, and snippets.

@zfdang
Forked from zemax/WindowsMove.ahk
Created June 11, 2022 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zfdang/174c0c00aa9e8474aa5d5500715ec13c to your computer and use it in GitHub Desktop.
Save zfdang/174c0c00aa9e8474aa5d5500715ec13c to your computer and use it in GitHub Desktop.
An AutoHotKey script to move & resize windows screen when pressing Win + Alt + Left or Win + Alt + Right. Window moves from 33% Left > 50% Left > 66% Left > 66% Right > 50% Right > 33% Right
;********************************************************************************
; Move Windows by 1/3
;********************************************************************************
MoveCycle(Add) {
static SizeCycle = 0
SizeCycle := Mod(SizeCycle + Add, 6)
if (SizeCycle < 0) {
SizeCycle := SizeCycle + 6
}
if (SizeCycle = 0) {
MoveWindow(0, 33.3333)
}
else if (SizeCycle = 1) {
MoveWindow(0, 50)
}
else if (SizeCycle = 2) {
MoveWindow(0, 66.6666)
}
else if (SizeCycle = 3) {
MoveWindow(33.3333, 66.6666)
}
else if (SizeCycle = 4) {
MoveWindow(50, 50)
}
else if (SizeCycle = 5) {
MoveWindow(66.6666, 33.3333)
}
}
MoveWindow(XP, WP) {
;Get current Window
WinGetActiveTitle, WinTitle
WinGetPos, X, Y, WinWidth, WinHeight, %WinTitle%
;Get Taskbar height
WinGetPos,,, tbW, tbH, ahk_class Shell_TrayWnd
;Calculate new position and size
XNew := (A_ScreenWidth * XP / 100)
WNew := (A_ScreenWidth * WP / 100)
HNew := (A_ScreenHeight - tbH)
;MsgBox, %XNew% - %WNew%
WinRestore, %WinTitle%
WinMove, %WinTitle%,, %XNew%, 0, %WNew%, %HNew%
}
#!Left::
MoveCycle(-1)
return
#!Right::
MoveCycle(1)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment