Code: Select all
; First press only RButton and define the area.
; Whenever the LButton is pressed additionally, the area can be moved.
; When RButton is released, the coordinates are displayed.
Mbutton:: ;FirstKey
ToolTip,% SelectArea("ms",SecondKey:="Button") ;ms = CoordMode Screen
Return
SelectArea(Options:="",SecondKey:="")
{ ; from Learning one, slightly modified
/*
Returns selected area. Return example: 22|13|243|543
Options: (White space separated)
- c color. Default: Blue.
- t transparency. Default: 50.
- g GUI number. Default: 99.
- m CoordMode. Default: s. s = Screen, r = Relative
Examples: SelectArea() , SelectArea("cLime t100 g55 mr")
*/
CoordMode, Mouse, Relative
MouseGetPos, rMX, rMY
CoordMode, Mouse, Screen
MouseGetPos, MX, MY
loop, parse, Options, %A_Space%
{
Field := A_LoopField
FirstChar := SubStr(Field,1,1)
if FirstChar contains c,t,g,m
{
StringTrimLeft, Field, Field, 1
%FirstChar% := Field
}
}
c := (c = "") ? "Blue" : c, t := (t = "") ? "50" : t, g := (g = "") ? "99" : g , m := (m = "") ? s : m
Gui %g%: Destroy
Gui %g%: +AlwaysOnTop -caption +Border +ToolWindow +LastFound
WinSet, Transparent, %t%
Gui %g%: Color, %c%
;Hotkey := RegExReplace(A_ThisHotkey,"^(\w* & |\W*)")
RegExMatch(A_ThisHotkey, "\W$|\w*$", Hotkey)
While, (GetKeyState(Hotkey, "p"))
{
Sleep, 10
MouseGetPos, MXend, MYend
IF GetKeyState(SecondKey,"P")
MX += MXend - MXOld, MY += MYend - MYOld
w := Abs(MX - MXend), h := Abs(MY - MYend)
X := Min(MX, MXOld:=MXend), Y := Min(MY, MYOld:=MYend)
Gui %g%: Show, x%X% y%Y% w%w% h%h% NA
}
Gui %g%: Destroy
if m = s ; Screen
{
MouseGetPos, MXend, MYend
If (MX > MXend)
temp := MX, MX := MXend, MXend := temp
If (MY > MYend)
temp := MY, MY := MYend, MYend := temp
Return MX " " MY " " MXend " " MYend
}
else ; Relative
{
CoordMode, Mouse, Relative
MouseGetPos, rMXend, rMYend
If (rMX > rMXend)
temp := rMX, rMX := rMXend, rMXend := temp
If (rMY > rMYend)
temp := rMY, rMY := rMYend, rMYend := temp
Return rMX " " rMY " " rMXend " " rMYend
}
}