Jump to content

Func _Middle Doesn't Work As Intended


Recommended Posts

Hi,

I'm trying to create a script to simply center any active window on screen when I press a shortcut. I found this "Func _Middle" (below) in the forums but it doesn't center it perfectly horizontally (always a little to right) and it doesn't take into consideration the size of the taskbar, so it stays too low. How can I change these values to center it perfectly in the screen taking into account the taskbar? I have played around with the values and looked for alternatives in the forums but found nothing. I also want it run at start up and hide the tray icon but I'll figure those things out later. :-)

HotKeySet("+1", "_Middle")
Func _Middle($win, $txt)
   $size = WinGetClientSize("", "")
   Local $y = (@DesktopHeight / 2) - ($size[1] / 2)
   Local $x = (@DesktopWidth / 2) - ($size[0] / 2)
   Return WinMove("", "", $x, $y)
EndFunc  ;==>_Middle
While 1
   Sleep (100)
WEnd
Link to comment
Share on other sites

Try this.

HotKeySet("+1", "_Middle") ; Press Shift and "1" keys, or, the "!" key to centre (Oxford dictionary) the active window.
HotKeySet("{ESC}", "Terminate") ; Perss Esc key to exit.

While 1
   Sleep (100)
WEnd


Func _Middle()
   ;$size = WinGetClientSize("", "")
   $size = WinGetPos("", "")
   Local $y = (@DesktopHeight / 2) - ($size[3] / 2)
   Local $x = (@DesktopWidth / 2) - ($size[2] / 2)
   WinMove("", "", $x, $y)
EndFunc  ;==>_Middle

Func Terminate()
    Exit
EndFunc   ;==>Terminate

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...