Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 2 down vote accepted 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

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


; The following function centers the specified window on the screen:
    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")
share|improve this answer
link only answers are discouraged, but feel free to apply the information that is in that link so that the answer is in your answer. – soandos Mar 21 '12 at 11:24
Why would you put something on the clipboard? – soandos Mar 21 '12 at 11:36
Thank you, I will give it a try. – Carlos Mar 22 '12 at 13:39

Using JohannesM's CenterWindow() function, this script centers the active window on the hotkey RightShift & C. The hotkey RightShift & B moves the centered window back to its original location, height and width.

To user the script, copy the code and save it as a .ahk file. I used the filename center active window_RShiftC_B.ahk

With Autohokey installed, run the script by double clicking on the file center active window_RShiftC_B.ahk

RShift & c::

global windowName
global X
global Y
global begWidth
global begHeight

WinGetTitle, windowName, A

WinGetPos, X, Y, begWidth, begHeight, %windowName%

    WinGetPos,,, Width, Height, %windowTitleVariable%
    WinMove, %windowTitleVariable%,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2    )-(Height/2)



RShift & b::

WinMove, %windowName%,, X, Y, begWidth, begHeight

share|improve this answer

These answers use title matching, which could apply to several windows. This will center only the active window, when you press win+c.

WinGetPos,,, sizeX, sizeY
WinMove, (A_ScreenWidth/2)-(sizeX/2), (A_ScreenHeight/2)-(sizeY/2)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.