Created
June 13, 2020 07:28
-
-
Save oasisfeng/f8ac4b7ede28046f4cefbfc2e10a06ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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