Hello!
This is my first time using AutoHotKey and I'm looking for a script to make a keyboard shortcut to center active window. And how to make it autostart with Windows. I'm on Windows 11.
Thanks!
Looking for a script to center active window in Windows 11
Re: Looking for a script to center active window in Windows 11
Use WinGetPos to determine the size of the window (specifying A for the WinTitle parameter to select the active window), then use A_ScreenWidth, A_ScreenHeight, and the appropriate math to determine where you need to move its upper-left corner using WinMove.
See Hotkeys for how to make a keyboard shortcut to trigger the code. To have the script launch with windows, right click on the script file and create a file shortcut, then move that shortcut to the Windows Startup folder.
See Hotkeys for how to make a keyboard shortcut to trigger the code. To have the script launch with windows, right click on the script file and create a file shortcut, then move that shortcut to the Windows Startup folder.
Re: Looking for a script to center active window in Windows 11
Thank you!
Here's the code that I ended up using.
Here's the code that I ended up using.
Code: Select all
#c::
SysGet Mon,MonitorWorkArea
WinGetPos ,,,wW,wH,A
WinMove A,,(MonRight-wW)/2,(MonBottom-wH)/2
Return
Re: Looking for a script to center active window in Windows 11
Do you know why this doesn't work in Windows 10?
Re: Looking for a script to center active window in Windows 11
It does work in Windows 10. If it doesn’t work for you, there are other reasons, such as the particular window you are trying to use or if you have multiple monitors or you didn’t press the correct hotkey (Win+C).
Re: Looking for a script to center active window in Windows 11
I had to add #SingleInstance,force.
Thank you & Happy New Year!
Thank you & Happy New Year!
Who is online
Users browsing this forum: Google [Bot] and 384 guests