Edit: Check out the buddy script, Window Control!
Screenshots:
Hotkeys:
1. Alt + LButton = Move control
2. Alt + Shift + LButton = Move control along X axis only
3. Alt + Ctrl + LButton = Move control along Y axis only
4. Alt + RButton = Resize
5. Alt + Shift + RButton = Resize control width only
6. Alt + Ctrl + RButton = Resize control height only
7. Alt + MButton OR Alt + Win + C = Change text within control
8. Alt + Shift + C: Copy control coordinates to clipboard
9. Win + LButton = Enable/Disable control
Code: Select all
#Persistent
#SingleInstance, Force
; Hotkeys
; 1. Alt + LButton = Move control
; 2. Alt + Shift + LButton = Move control along X axis only
; 3. Alt + Ctrl + LButton = Move control along Y axis only
; 4. Alt + RButton = Resize
; 5. Alt + Shift + RButton = Resize control width only
; 6. Alt + Ctrl + RButton = Resize control height only
; 7. Alt + MButton OR Alt + Win + C = Change text within control
; 8. Alt + Shift + C: Copy control coordinates to clipboard
; 9. Win + LButton = Enable/Disable control
Menu, TRAY, NoStandard
Menu, TRAY, MainWindow ; For compiled scripts
Menu, TRAY, Add, &Reload, Reload
Menu, TRAY, Add, E&xit, Exit
CoordMode, Mouse
SetControlDelay, -1
return ; End auto-execute
Reload:
Reload
Exit:
ExitApp
#!c::
{
gosub ChangeControlLabel
return
}
; Simple hotkeys like ~Alt & ~LButton cannot be used becuase this does not disable clicks inside of windows
Shift & ~Alt::
Ctrl & ~Alt::
~Alt::
{
Hotkey, *LButton, Alt_And_LButton, On
Hotkey, *RButton, Alt_And_RButton, On
Hotkey, *MButton, ChangeControlLabel, On
KeyWait, Alt
Hotkey, *LButton, Off
Hotkey, *RButton, Off
Hotkey, *MButton, Off
if (A_ThisHotkey = "*LButton")
gosub Alt_And_LButton
else if (A_ThisHotkey = "*RButton")
gosub Alt_And_RButton
else if (A_ThisHotkey = "*MButton")
gosub ChangeControlLabel
return
}
Alt_And_LButton:
{
iPrevMouseX := iPrevMouseY := A_Blank
MouseGetPos,,,, hCtrl, 2
while (GetKeyState("Alt", "P") && GetKeyState("LButton", "P"))
{
bIgnoreX := GetKeyState("Ctrl", "P")
bIgnoreY := GetKeyState("Shift", "P")
MouseGetPos, iMouseX, iMouseY
iMouseX := iMouseX
iMouseY := iMouseY
ControlGetPos, iX, iY,,,, ahk_id %hCtrl%
iXDelta := bIgnoreX ? 0 : iMouseX - (iPrevMouseX == A_Blank ? iMouseX : iPrevMouseX)
iYDelta := bIgnoreY ? 0 : iMouseY - (iPrevMouseY == A_Blank ? iMouseY : iPrevMouseY)
if (iXDelta <> 0 || iYDelta <> 0)
{
ControlMove,, iX + iXDelta, iY + iYDelta,,, ahk_id %hCtrl%
DllCall("RedrawWindow", "Ptr", hCtrl, "Ptr", 0, "Ptr", 0, "UInt", RDW_INVALIDATE := 1 | RDW_ERASENOW := 0x200 | RDW_ERASE := 4)
}
iPrevMouseX := iMouseX
iPrevMouseY := iMouseY
}
return
}
Alt_And_RButton:
{
iPrevMouseX := iPrevMouseY := A_Blank
MouseGetPos,,,, hCtrl, 2
while (GetKeyState("Alt", "P") && GetKeyState("RButton", "P"))
{
bIgnoreW := GetKeyState("Ctrl", "P")
bIgnoreH := GetKeyState("Shift", "P")
MouseGetPos, iMouseX, iMouseY
iMouseX := iMouseX
iMouseY := iMouseY
ControlGetPos,,, iW, iH,, ahk_id %hCtrl%
iWDelta := bIgnoreW ? 0 : iMouseX - (iPrevMouseX == A_Blank ? iMouseX : iPrevMouseX)
iHDelta := bIgnoreH ? 0 : iMouseY - (iPrevMouseY == A_Blank ? iMouseY : iPrevMouseY)
if (iWDelta <> 0 || iHDelta <> 0)
{
ControlMove,,,, iW + iWDelta, iH + iHDelta, ahk_id %hCtrl%
DllCall("RedrawWindow", "Ptr", hCtrl, "Ptr", 0, "Ptr", 0, "UInt", RDW_INVALIDATE:=1 | RDW_ERASENOW:=0x200 | RDW_ERASE:=4)
}
iPrevMouseX := iMouseX
iPrevMouseY := iMouseY
}
return
}
ChangeControlLabel:
{
; Turn off hotkeys so that the LButton is not responise
Hotkey, *LButton, Off
Hotkey, *RButton, Off
Hotkey, *MButton, Off
; This hotkey seems to be triggered twice every time it is activated, so g_iTimeAtThisExecution is used to prevent double-execution
g_iTimeAtThisExecution := SubStr(A_Now, StrLen(A_Now) - 3, 4)
if (A_ThisHotkey = "*MButton" && g_iTimeAtLastExecution != A_Blank && g_iTimeAtThisExecution - g_iTimeAtLastExecution < 1)
return
MouseGetPos,,,, hCtrl, 2
ControlGetText, sExistingText,, ahk_id %hCtrl%
InputBox, sText, Set Control Text,,,,,,,,, %sExistingText%
g_iTimeAtLastExecution := SubStr(A_Now, StrLen(A_Now) - 3, 4)
if (ErrorLevel)
return
ControlSetText,, %sText%, ahk_id %hCtrl%
return
}
#LButton::
{
MouseGetPos,,,, hCtrl, 2
ControlGet, bEnabled, Enabled,,, ahk_id %hCtrl%
Control, % bEnabled ? "Disable" : "Enable",,, ahk_id %hCtrl%
return
}
!+C::
{
MouseGetPos,,,, hCtrl, 2
ControlGetText, sCtrlTxt,, ahk_id %hCtrl%
ControlGetPos, iX, iY, iW, iH,, ahk_id %hCtrl%
if !((iX == A_Blank || iY == A_Blank || iW == A_Blank || iH == A_Blank))
clipboard := "Control:`t" sCtrlTxt "`nLeft:`t" iX "`nTop:`t" iY "`nRight:`t" iW "`nBottom:`t" iH
return
}