# Region determine

2 replies to this topic

### #1 Jex

Jex

Polymath

• Active Members
• 206 posts

Posted 06 November 2007 - 06:01 AM

That function useable for create screenshot capture scripts or like that things.

AutoIt
```#include <GUIConstants.au3>
#include <Misc.au3>
#include <ScreenCapture.au3>

\$Region = Region(1)
Example3()

Func Example1()
MsgBox("", "", "X (Left) : " & \$Region[0] & "  | Y (Up) : " & \$Region[1] & @CRLF & "X (Right) : " & \$Region[2] & "  | Y (Down) : " & \$Region[3] & @CRLF & "Region size : " & \$Region[4] & " x " & \$Region[5])
EndFunc   ;==>Example1

Func Example2()
\$Pixel = PixelSearch(\$Region[0], \$Region[1], \$Region[2], \$Region[3], 0x84A35B)
If Not @error Then MouseMove(\$Pixel[0], \$Pixel[1], 0)
EndFunc   ;==>Example2

Func Example3()
_ScreenCapture_Capture (@MyDocumentsDir & "\Test.jpg", \$Region[0], \$Region[1], \$Region[2], \$Region[3])
ShellExecute(@MyDocumentsDir & "\Test.jpg")
EndFunc   ;==>Example3

Func Region(\$Tray = 0)
\$Invisible = GUICreate("", 100, 100, -1, -1, \$WS_POPUP, \$WS_EX_TOPMOST)
WinSetTrans(\$Invisible, "", 1)
GUISetState(@SW_SHOW, \$Invisible)
While 1
Local \$Pos1 = MouseGetPos()
WinMove(\$Invisible, "", \$Pos1[0] - 50, \$Pos1[1] - 50)
If \$Tray = 1 Then TrayTip("", "X (Left) : " & \$Pos1[0] & "  | Y (Up) : " & \$Pos1[1], 1, 16)
If _IsPressed("01") Then
GUIDelete(\$Invisible)
Local \$Pos1 = MouseGetPos(), \$x1, \$x2, \$y1, \$y2
\$RegionGUI = GUICreate("", 1, 1, \$Pos1[0], \$Pos1[1], BitOR(\$WS_POPUP, \$WS_BORDER), \$WS_EX_TOPMOST)
WinSetTrans(\$RegionGUI, "", 50)
GUISetState(@SW_SHOW, \$RegionGUI)
Do
Local \$Pos2 = MouseGetPos()
If \$Pos2[0] < \$Pos1[0] And \$Pos2[1] < \$Pos1[1] Then
\$x2 = \$Pos1[0]
\$y2 = \$Pos1[1]
\$x1 = \$Pos2[0]
\$y1 = \$Pos2[1]
ElseIf \$Pos2[0] > \$Pos1[0] And \$Pos2[1] < \$Pos1[1] Then
\$x1 = \$Pos1[0]
\$y2 = \$Pos1[1]
\$x2 = \$Pos2[0]
\$y1 = \$Pos2[1]
ElseIf \$Pos2[0] > \$Pos1[0] And \$Pos2[1] > \$Pos1[1] Then
\$x1 = \$Pos1[0]
\$y1 = \$Pos1[1]
\$x2 = \$Pos2[0]
\$y2 = \$Pos2[1]
ElseIf \$Pos2[0] < \$Pos1[0] And \$Pos2[1] > \$Pos1[1] Then
\$x2 = \$Pos1[0]
\$y1 = \$Pos1[1]
\$x1 = \$Pos2[0]
\$y2 = \$Pos2[1]
EndIf
WinMove(\$RegionGUI, "", \$x1, \$y1, \$x2 - \$x1, \$y2 - \$y1)
If \$Tray = 1 Then TrayTip("", "X (Left) : " & \$x1 & "  | Y (Up) : " & \$y1 & @CRLF & "X (Right) : " & \$x2 & "  | Y (Down) : " & \$y2 & @CRLF & "Region size : " & \$x2 - \$x1 & " x " & \$y2 - \$y1, 1, 16)
Until Not _IsPressed("01")
TrayTip("", "", 0)
GUIDelete(\$RegionGUI)
ExitLoop
EndIf
WEnd
Local \$Pos3[6] = [\$x1, \$y1, \$x2, \$y2, \$x2 - \$x1, \$y2 - \$y1]
Return \$Pos3
EndFunc   ;==>Region```

Edited by Jex, 07 November 2007 - 10:36 AM.

### #2 James

James

jbrooksuk

• MVPs
• 9,470 posts

Posted 06 November 2007 - 01:36 PM

That looks really cool Jex. Nice script!

### #3 Jex

Jex

Polymath

• Active Members
• 206 posts

Posted 07 November 2007 - 10:39 AM

Thanks for your comment. I'm added one more example and changed little region function.

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users