freat_cuvox Posted April 14, 2018 Share 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 Link to comment Share on other sites More sharing options...
kaisies Posted April 14, 2018 Share 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 Link to comment Share on other sites More sharing options...
Malkey Posted April 14, 2018 Share 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 Link to comment Share on other sites More sharing options...
freat_cuvox Posted April 15, 2018 Author Share Posted April 15, 2018 That did it! Thanks Malkey! Link to comment Share on other sites More sharing options...
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