Screenshot on condition

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
bbock727
Newbie
Posts: 2
Joined: Wed Jun 15, 2016 12:13 am

Screenshot on condition

Post by bbock727 » Fri Jun 17, 2016 4:04 am

New to the program and i am looking for some help with the screen capture function.

Here is the script im using:

Code: Select all

//Find FIRST image
FindImagePos>C:\x.bmp,SCREEN,.99,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  //If FIRST image found, get position of image TWO and click on THAT
  FindImagePos>C:\y.bmp,SCREEN,0.9,1,XArr,YArr,NumFound,CCOEFF
  If>Image2Found>0
    MouseMove>XArr_0,YArr_0
    LClick
    Let>FoundAnImage=TRUE
  Endif
Endif
I want to add a function to screenshot the area of x.bmp when its found and before it clicks y.bmp.
A few questions:

1) How do i make it so macro scheduler will take screenshots in succession and name them differently.
2) How do i define the size and coordinates of the screenshot (its going to be a little bigger than the x.bmp, honestly i dont care if it takes a full screenshot of the whole desktop if necessary, but it doesnt need to capture that much).

Any help would be appreciated... if you can write the part that needed completely that would be even better.

Thanks

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Screenshot on condition

Post by hagchr » Fri Jun 17, 2016 9:18 am

Hi, You can add a date/time stamp to the name of the file to keep them separate. For the size, if you know the size of your target bmp then for FindImagePos> then there is a parameter to get the top left position and then you just add something to it, see example below. If you need it to be dynamic you could use FindImagePos> twice, first to find the top left position and then to find the bottom right position and feed that into the ScreenCapture>command.

Different ways to solve it, one way could be to define a Subroutine (SRT>CreateScreenShot) and call it after your If>NumFound>0, using Gosub>CreateScreenShot. Hope if helps.

Code: Select all

SRT>CreateScreenShot
    //Focus the relevant screen
    SetFocus>xxx
    WaitWindowOpen>xxx

    //Define size of picture, add x,y from top left
    Let>XArr1_0={%XArr_0%+500}
    Let>YArr1_0={%YArr_0%+200}

    //Create date/time stamp to add to file name
    CODEBLOCK
        Year>yy
        Month>mm
        Day>dd
        Let>date=%yy%%mm%%dd%

        Hour>hh
        Min>mm
        Sec>ss
        Let>time=%hh%%mm%%ss%
    ENDCODEBLOCK
    
    Let>FileName=%BMP_DIR%\x_%date%_%time%.jpg

    //Focus the relevant screen
    SetFocus>xxx
    WaitWindowOpen>xxx
    
    ScreenCapture>%XArr_0%,%YArr_0%,%XArr1_0%,%YArr1_0%,FileName
END>CreateScreenShot

bbock727
Newbie
Posts: 2
Joined: Wed Jun 15, 2016 12:13 am

Re: Screenshot on condition

Post by bbock727 » Fri Jun 17, 2016 3:26 pm

Thank you for your help. Unfortunately i am an extreme novice in scripting. The script I showed you is actually part of a large script that is just looking for specific images and then clicking based on what image it sees.

I really have no idea how to integrate the code you wrote into my script. Any help would be greatly appreciated. I could even send you my script in an email if you are willing to help and thats easier.

Thanks again.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts