Jump to content

Region determine


Jex
 Share

Recommended Posts

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

Posted Image

#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
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...