freat_cuvox Posted April 14, 2018 Posted April 14, 2018 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
kaisies Posted April 14, 2018 Posted April 14, 2018 Look into winapi getsystemmetrics. Don't remember which one specifically as I'm on mobile, but it'd pretty obvious from what I remember
Malkey Posted April 14, 2018 Posted April 14, 2018 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now