Center Window - Won't Work With Adobe

Share your favorite FastKeys commands
Post Reply
gsechler
Posts: 8
Joined: Dec 7th, ’18, 19:38

Post by gsechler » Sep 25th, ’24, 22:38

Hello,

I believe I found the following script previously in this forum or another similar forum online. I have an ultra-wide screen monitor, so sometimes I like to center the window to make it a bit easier to read. This script works perfectly with everything except Adobe Acrobat. No matter what document I have open, it will not work. Does anybody have any clues on how to fix that?

Also, for some reason, the window doesn't actually center on Y-axis on my screen. It's about 20 pixels off for some reason. That's why the - 20 is there.

Code: Select all

 WinGetTitle, ActiveWindowTitle, A ; Get the active window's title for "targetting" it/acting on it.
 WinGetPos,,, Width, Height, %ActiveWindowTitle% ; Get the active window's position, used for our calculations.

 TargetX := (A_ScreenWidth/2)-(Width/2) ; Calculate the horizontal target where we'll move the window.
 TargetY := (A_ScreenHeight/2)-(Height/2) - 20 ; Calculate the horizontal target where we'll move the window. 

 WinMove, %ActiveWindowTitle%,, %TargetX%, %TargetY% ; Move the window to the calculated coordinates.
 
return
Thanks!
User avatar
Marko
Posts: 1808
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Oct 1st, ’24, 19:10

Does this work?

Code: Select all

WinGetPos,,, Width, Height, A
WinMove A,, (A_ScreenWidth-Width)/2, (A_ScreenHeight-Height)/2
or

Code: Select all

SysGet Mon, MonitorWorkArea
WinGetPos,,, Width, Height, A
WinMove A,, (MonRight-Width)/2, (MonBottom-Height)/2
gsechler
Posts: 8
Joined: Dec 7th, ’18, 19:38

Post by gsechler » Oct 4th, ’24, 02:45

Second one works perfectly! Thanks so much for the help!
Post Reply