Skip to content

Instantly share code, notes, and snippets.

@schellingb
Created April 12, 2020 13:39
Show Gist options
  • Save schellingb/7742fe9d3ac63c6802f1f64180ba1eb6 to your computer and use it in GitHub Desktop.
Save schellingb/7742fe9d3ac63c6802f1f64180ba1eb6 to your computer and use it in GitHub Desktop.
AutoHotkey - Easy Window Dragging - left button moves window, middle button resizes it
; Easy Window Dragging - left button moves window, middle button resizes it
ScrollLock & LButton::
ScrollLock & MButton::
CoordMode, Mouse ; switch to screen/absolute coordinates
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY, EWD_OriginalPosW, EWD_OriginalPosH, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
IfNotEqual, EWD_WinState, 0, return ; Do nothing if the window is maximized/minimized
SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
return
EWD_WatchMouse:
GetKeyState, EWD_LButtonState, LButton, P
GetKeyState, EWD_MButtonState, MButton, P
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
SetWinDelay, -1 ; makes the below move faster/smoother.
if (EWD_LButtonState == "D")
WinMove, ahk_id %EWD_MouseWin%,, EWD_OriginalPosX + EWD_MouseX - EWD_MouseStartX, EWD_OriginalPosY + EWD_MouseY - EWD_MouseStartY
if (EWD_MButtonState == "D")
WinMove, ahk_id %EWD_MouseWin%,,,,EWD_OriginalPosW + EWD_MouseX - EWD_MouseStartX, EWD_OriginalPosH + EWD_MouseY - EWD_MouseStartY
if (EWD_LButtonState == "D" or EWD_MButtonState == "D")
return ; mouse button still down, continue timer
if (EWD_MouseX == EWD_MouseStartX and EWD_MouseY == EWD_MouseStartY)
{
; Mouse clicked but didn't move toggles window title bar visibility
WinGet, tStyle, Style, A
if (tStyle & 0xC40000)
WinSet, Style, -0xC40000, A
else
WinSet, Style, +0xC40000, A
WinMove, A,,,, EWD_OriginalPosW+1, EWD_OriginalPosH+1
WinMove, A,,,, EWD_OriginalPosW, EWD_OriginalPosH
}
SetTimer, EWD_WatchMouse, Off
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment