Sign in to follow this  
Followers 0
xdp22

Screen capture x y z

3 posts in this topic

#1 ·  Posted (edited)

Sorry for bad englisch i will use translator.

Hello, i have one problem, i need to make screen capture, but it's not normal screen capture function. In ScreenCapture UDF it's possible to say screen cordinates, but i need to make it automatic, example :

Let's say we have a picture of him as a man, but we want to program only took a picture of an item, this program is to shoot the image area in which you hit the square may be defined volume of 300 to 300, that is, for example, you press on your head man, is a program that takes a picture the place where you push the area 300 on 300th Is it possible? for example, using mousegetpos + a few other functions?

This is example code but i dont know how it works, i just found that at google.

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <ScreenCapture.au3>

Global $hDLL = DllOpen("User32.dll")

Global $Drag = False
Global $aCoord_Start
Global $aCoord_End
Global $iLeft, $iTop, $iRight, $iBottom
Global $sCapture = False

HotKeySet("{Esc}", "_Exit")

Global $pStub_MouseProc = DllCallbackRegister ("_Mouse_Handler", "int", "int;ptr;ptr")

Global $hHookMouse = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($pStub_MouseProc), _WinAPI_GetModuleHandle(0), 0)

While 1
    If $sCapture Then
        $sCapture = False
        _ScreenCapture_Capture(@ScriptDir & "\Capture.jpg", $iLeft, $iTop, $iRight, $iBottom)
    EndIf
    Sleep(100)
WEnd

Func _Mouse_Handler($nCode, $wParam, $lParam)
    If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHookMouse, $nCode, $wParam, $lParam)

    Switch $wParam
        Case $WM_LBUTTONDOWN
            $aCoord_Start = MouseGetPos()
        Case $WM_MOUSEMOVE
            If _IsPressed("01", $hDLL) Then $Drag = True
        Case $WM_LBUTTONUP
            $aCoord_End = MouseGetPos()

            If $Drag = True Then
                $Drag = False

                If $aCoord_Start[0] < $aCoord_End[0] Then
                    $iLeft = $aCoord_Start[0]
                    $iRight = $aCoord_End[0]
                Else
                    $iLeft = $aCoord_End[0]
                    $iRight = $aCoord_Start[0]
                EndIf

                If $aCoord_Start[1] < $aCoord_End[1] Then
                    $iTop = $aCoord_Start[1]
                    $iBottom = $aCoord_End[1]
                Else
                    $iTop = $aCoord_End[1]
                    $iBottom = $aCoord_Start[1]
                EndIf

                $sCapture = True
                Return 0
            EndIf
    EndSwitch

    Return _WinAPI_CallNextHookEx($hHookMouse, $nCode, $wParam, $lParam)
EndFunc

Func _Exit()
    DllCallbackFree($pStub_MouseProc)
    _WinAPI_UnhookWindowsHookEx($hHookMouse)
    DllClose($hDLL)

    Exit
EndFunc
Edited by xdp22

Share this post


Link to post
Share on other sites



xdp22,

No need to use anything as complicated as that! :x

This does what I believe you want:

#Include <ScreenCapture.au3>
#include <Misc.au3>

$dll = DllOpen("user32.dll")

; Create exit mode
HotKeySet("{ESC}", "On_Exit")

While 1

    ; Wait for mouse click
    If _IsPressed("01", $dll) Then
        ; Get mouse position
        $aMPos = MouseGetPos()
        ; Determine coordinates to make a 300x300 square around the mouse position
        $iLeft   = $aMPos[0] - 150
        $iTop    = $aMPos[1] - 150
        $iRight  = $aMPos[0] + 150
        $iBottom = $aMPos[1] + 150
        ; Capture that area
        _ScreenCapture_Capture("My_Image.jpg", $iLeft, $iTop, $iRight, $iBottom)
        ; Wait until the mouse is released - or we take too many pictures!!!
        Do
            Sleep(10)
        Until Not(_IsPressed("01", $dll))

    EndIf

WEnd

Func On_Exit()
    DllClose($dll)
    Exit
EndFunc

If it does not, or you have any questions, please come back. :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

That is perfect, thank you very much! :x

Edited by xdp22

Share this post


Link to post
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
Sign in to follow this  
Followers 0