-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathLetUserSelectRect.ahk
55 lines (51 loc) · 1.41 KB
/
LetUserSelectRect.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
#NoEnv
CoordMode, Mouse ; Required: change coord mode to screen vs relative.
LetUserSelectRect(x1, y1, x2, y2)
MsgBox %x1%,%y1% %x2%,%y2%
ExitApp
*/
LetUserSelectRect(ByRef X1, ByRef Y1, ByRef X2, ByRef Y2) {
static r := 3
; Create the "selection rectangle" GUIs (one for each edge).
Loop 4 {
Gui, %A_Index%: -Caption +ToolWindow +AlwaysOnTop
Gui, %A_Index%: Color, Red
}
; Disable LButton.
Hotkey, *LButton, lusr_return, On
; Wait for user to press LButton.
KeyWait, LButton, D
; Get initial coordinates.
MouseGetPos, xorigin, yorigin
; Set timer for updating the selection rectangle.
SetTimer, lusr_update, 10
; Wait for user to release LButton.
KeyWait, LButton
; Re-enable LButton.
Hotkey, *LButton, Off
; Disable timer.
SetTimer, lusr_update, Off
; Destroy "selection rectangle" GUIs.
Loop 4
Gui, %A_Index%: Destroy
return
lusr_update:
MouseGetPos, x, y
if (x = xlast && y = ylast)
; Mouse hasn't moved so there's nothing to do.
return
if (x < xorigin)
x1 := x, x2 := xorigin
else x2 := x, x1 := xorigin
if (y < yorigin)
y1 := y, y2 := yorigin
else y2 := y, y1 := yorigin
; Update the "selection rectangle".
Gui, 1:Show, % "NA X" x1 " Y" y1 " W" x2-x1 " H" r
Gui, 2:Show, % "NA X" x1 " Y" y2-r " W" x2-x1 " H" r
Gui, 3:Show, % "NA X" x1 " Y" y1 " W" r " H" y2-y1
Gui, 4:Show, % "NA X" x2-r " Y" y1 " W" r " H" y2-y1
lusr_return:
return
}