Skip to content

Instantly share code, notes, and snippets.

@oasisfeng
Created June 13, 2020 07:28
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 oasisfeng/f8ac4b7ede28046f4cefbfc2e10a06ad to your computer and use it in GitHub Desktop.
Save oasisfeng/f8ac4b7ede28046f4cefbfc2e10a06ad to your computer and use it in GitHub Desktop.
#!Space::CenterActiveWindow() ; Win+Alt+Space
CenterActiveWindow()
{
winHandle := WinExist("A")
VarSetCapacity(monitorInfo, 40)
NumPut(40, monitorInfo)
monitorHandle := DllCall("MonitorFromWindow", "uint", winHandle, "uint", 0x2)
DllCall("GetMonitorInfo", "uint", monitorHandle, "uint", &monitorInfo)
A_Left := NumGet(monitorInfo, 20, "Int")
A_Top := NumGet(monitorInfo, 24, "Int")
A_Right := NumGet(monitorInfo, 28, "Int")
A_Bottom := NumGet(monitorInfo, 32, "Int")
WinGetPos,,, Width, Height, ahk_id %winHandle%
winX := A_Left + (A_Right - A_Left - Width) / 2
winY := A_Top + (A_Bottom - A_Top - Height) / 2
WinMove, A,, winX, winY
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment