AutoHotkey – Center Active Window Script

autohotkey

I'm looking for a way to center the active window on the desktop using Autohotkyes. Can someone give me a script that I could use please.
Thanks

Best Answer

http://www.autohotkey.com/docs/commands/WinMove.htm was the first result on google with the phrase "autohotkey center window". It may help you out. See the example script.

Example Script

Run, calc.exe
WinWait, Calculator
WinMove, 0, 0 ; Move the window found by WinWait to the upper-left corner of the screen.

SplashTextOn, 400, 300, Clipboard, The clipboard contains:`n%clipboard%
WinMove, Clipboard, , 0, 0 ; Move the splash window to the top left corner. 
Msgbox, Press OK to dismiss the SplashText
SplashTextOff

; The following function centers the specified window on the screen:
CenterWindow(WinTitle)
{
    WinGetPos,,, Width, Height, %WinTitle%
    WinMove, %WinTitle%,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)
}

Customized

; The following function centers the specified window on the screen:
CenterWindow(WinTitle)
{
    WinGetPos,,, Width, Height, %WinTitle%
    WinMove, %WinTitle%,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)
    ;Msgbox, Made the Notepad Center?
}

Run, file.exe

CenterWindow("title of file.exe")
Related Question