Created
January 22, 2023 17:30
-
-
Save gmcabrita/a5bb828b0c178e2919c47b32437a3f3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DetectHiddenWindows True | |
EXCEPT:="Progman WorkerW Shell_TrayWnd" | |
#!LButton:: | |
{ | |
moveActiveWindow | |
Return | |
} | |
#!RButton:: | |
{ | |
resizeActiveWindow | |
Return | |
} | |
#!MButton:: | |
{ | |
resizeActiveWindowTo1080p | |
Return | |
} | |
moveActiveWindow() { | |
Critical ; Reduce the risk of interruption. | |
Local hWnd | |
MouseGetPos(, , &hWnd) | |
Class := WinGetClass("ahk_id" . WinExist("ahk_id" . hWnd)) | |
If (DllCall("IsZoomed", "Ptr", hWnd) || InStr(" " . EXCEPT . " ", " " . Class . " ", True)) | |
Return | |
WinActivate() | |
WinWaitActive(, , 0) | |
PostMessage(0x112, 0xF010) ; WM_SYSCOMMAND, SC_MOVE | |
; The Move option does not automatically track the mouse position | |
; until you've pressed an arrow key at least once. Can't use Send | |
; because the WM_SYSCOMMAND message would interrupt it. | |
PostMessage(0x100, 0x25) ; WM_KEYDOWN, VK_LEFT | |
PostMessage(0x101, 0x25) ; WM_KEYUP, VK_LEFT | |
PostMessage(0x100, 0x27) ; WM_KEYDOWN, VK_RIGHT | |
PostMessage(0x101, 0x27) ; WM_KEYUP, VK_RIGHT | |
} | |
resizeActiveWindow() { | |
Critical ; Reduce the risk of interruption. | |
Local hWnd | |
MouseGetPos(, , &hWnd) | |
Class := WinGetClass("ahk_id" . WinExist("ahk_id" . hWnd)) | |
If (DllCall("IsZoomed", "Ptr", hWnd) || InStr(" " . EXCEPT . " ", " " . Class . " ", True)) | |
Return | |
WinActivate() | |
WinWaitActive(, , 0) | |
PostMessage(0x112, 0xF000) ; WM_SYSCOMMAND, SC_SIZE | |
; The Size option does not automatically track the mouse position | |
; until you've pressed an arrow key at least once. Can't use Send | |
; because the WM_SYSCOMMAND message would interrupt it. | |
; | |
; We use Right and Bottom to begin a resize using the bottom right corner of the window | |
PostMessage(0x100, 0x27) ; WM_KEYDOWN, VK_RIGHT | |
PostMessage(0x101, 0x27) ; WM_KEYUP, VK_RIGHT | |
PostMessage(0x100, 0x28) ; WM_KEYDOWN, VK_BOTTOM | |
PostMessage(0x101, 0x28) ; WM_KEYUP, VK_BOTTOM | |
} | |
resizeActiveWindowTo1080p() { | |
Critical ; Reduce the risk of interruption. | |
Local hWnd | |
MouseGetPos(, , &hWnd) | |
Class := WinGetClass("ahk_id" . WinExist("ahk_id" . hWnd)) | |
If (DllCall("IsZoomed", "Ptr", hWnd) || InStr(" " . EXCEPT . " ", " " . Class . " ", True)) | |
Return | |
WinActivate() | |
WinWaitActive(, , 0) | |
WinGetPos(&X, &Y, &W, &H, "A") | |
WinMove(X, Y, 1920, 1080, "A") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment