Skip to content

Instantly share code, notes, and snippets.

@gmcabrita
Created January 22, 2023 17:30
Show Gist options
  • Save gmcabrita/a5bb828b0c178e2919c47b32437a3f3e to your computer and use it in GitHub Desktop.
Save gmcabrita/a5bb828b0c178e2919c47b32437a3f3e to your computer and use it in GitHub Desktop.
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