SRT Clicking

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Tertium
Newbie
Posts: 5
Joined: Sun Aug 23, 2015 12:41 pm

SRT Clicking

Post by Tertium » Sun Aug 23, 2015 12:56 pm

Hello, im quite new to macro scheduler at the moment im runing the 14 trial version and i quite like it but im stuck at something since im no programer and this is the first time trying something like this or any code in general even tough its quite easy to understand some commads some are ad bit hard so i finaly decided to ask for a bit of help after not having any luck finding what im looking for and that is:

Im trying to get a subrouting to click an image but wen i use to SRT to be able to imput the nr of clicks it should give to the image found

something like:

Code: Select all

Gosub>Test,"Nr of clicks it should give to the image"


SRT>Test
  FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif
END>Test
Is something like that possible? If so how you do it?

Also is there anyway of executing a script normaly and wen a image appears to do something and after that to resume where the script left?

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

Re: SRT Clicking

Post by hagchr » Sun Aug 23, 2015 3:15 pm

Hi, here some lines that hopefully will help you (you can adjust wait> depending on what you are clicking on). Remember to make sure you focus on the right window (I added SetFocus> which you can update).

For the second question, you could probably use onEvent> which will trigger an SRT depending on some event, either standard (eg when a window opens, a file exists, a key is pressed etc) or custom (which could be like almost anything, eg something appearing up on the screen).

Code: Select all

Let>clicks=3
Gosub>Test,clicks

Wait>5

SRT>Test
    //SetFocus>The window you want to click on
    
    FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
   
    If>NumFound>0
        MouseMove>XArr_0,YArr_0
        Let>ct=0
        While>ct<Test_VAR_1
            Add>ct,1
            LClick
            Wait>1
        EndWhile
    Endif
END>Test

Tertium
Newbie
Posts: 5
Joined: Sun Aug 23, 2015 12:41 pm

Re: SRT Clicking

Post by Tertium » Sun Aug 23, 2015 5:14 pm

Thank you those lines are exactly what i wanted thank you!

Also if you dont mind how do you create a custom onEvent handler that wen a image will apear will do a something? Is it possible?

1 more question i have tried to use the lines of codes that i got from you very usefull thank again but how do i make them to get the numfound value from other subroutine?

Code: Select all

GoSub>Beggining
Let>clicks=1
Gosub>Test,clicks

Wait>0.5
For example to take the NumFound from the srt Beggining

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

Re: SRT Clicking

Post by hagchr » Sun Aug 23, 2015 6:22 pm

Hi, for the onEvent> the structure would be something like this:

Code: Select all

onEvent>CUSTOM,myTriggerSub,DoIT,DoSomething

Label>Main
    Wait>0.2
Goto>Main

SRT>myTriggerSub
    FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
    If>NumFound>0
        Let>DoIT=TRUE
    Endif
END>myTriggerSub

SRT>DoSomething
    MDL>Found it on screen!!
    Let>DoIT=False
END>DoSomething
In your Beggining SRT you can set clicks to something eg 1. Since it is a global variable it will be available later in the Test SRT. So something like this:

Code: Select all

GoSub>Beggining
Gosub>Test,clicks
Wait>0.5


SRT>Beggining
    //...
    //...  
    Let>clicks=1
END>Beggining

Tertium
Newbie
Posts: 5
Joined: Sun Aug 23, 2015 12:41 pm

Re: SRT Clicking

Post by Tertium » Sun Aug 23, 2015 6:42 pm

Thank you for the responses!

Few more questions if you dont mind!

Code: Select all

onEvent>CUSTOM,myTriggerSub,DoIT,DoSomething

Label>Main
    Wait>0.2
Goto>Main

SRT>myTriggerSub
    FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
    If>NumFound>0
        Let>DoIT=TRUE
    Endif
END>myTriggerSub

SRT>DoSomething
    MDL>Found it on screen!!
    Let>DoIT=False
END>DoSomething
Here wont the code spin in a loop at label main goto main?

Also at the second by seting clicks into the srt of beggining that ok thanks but i will use the same thing for continue and il use continue several times in the scrip sometimes i want to click only 2 times others 1 other time 3 and so on wen i call the SRT is there any way?

I mean.... ...... ... ... .... .....

Code: Select all

GoSub>Continue
Let>clicks=1
Gosub>Test,clicks

Wait>0.5
And in the same script i would like to use it few more times but this time to give diferit amo of clicks

Code: Select all

GoSub>Continue
Let>clicks=3
Gosub>Test,clicks

Wait>0.5
And so on so i cant set in continue the clicks because that means i could not use it again

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

Re: SRT Clicking

Post by hagchr » Sun Aug 23, 2015 7:05 pm

The onEvent> is looking for the picture only as long as the program is running. So either the program needs to be doing something else or you need some kind of loop to keep it active. (There is also possible to set a trigger for a whole script - under the Trigger tab).

Ok, I understand clicks will change so you don't want to set it in the SRT. Question, where/how do you define how many clicks you want to do? If it is based on NumFound then that is also a global variable and can be used.

Tertium
Newbie
Posts: 5
Joined: Sun Aug 23, 2015 12:41 pm

Re: SRT Clicking

Post by Tertium » Sun Aug 23, 2015 8:02 pm

Ok i understand the logic behind the onEvent now but if the loop is there it will be able to execute the rest of the program even if the loop its set its not like wen it reaches it goes to the end of the loop and then restarts the loop and never executes the rest of the scrip?



And well basicaly i have done something similar to this in the script wen i have done it first time :

Code: Select all

Gosub>Continue
Lclick
Lclick
Llick
Gosub>ABC
Lclick
GoSub>Continue
LClick
LClick
GoSub>ARD
RClick

Had the subs to move the mouse where i wanted and after i have just imputed the clicks i wanted but that can go wrong

Basicaly there is a image that randomly appears and you got to click on it wen it appears sometimes its 2 times other time 3 other 4 other time 1 and so on. And its behaivor its someting like a dialog box where you have to press continue to move to next page so it differ from time to time of how many clicks you need to reach the end.

And dont think its based on the numfound since it the numfound wen the image appears would be 1 but after 1click the image will appear again its not like theres 2 images in the same time on the screen. Also i cant set focus to that dialog box since the box its a box inside a flash player program.

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

Re: SRT Clicking

Post by hagchr » Tue Aug 25, 2015 8:51 am

Hi, you need to think through which images you are looking for and when, eg

If image1 comes then it must be followed by image2 (eg continue) or image3 (eg cancel)
If image4 comes then it must be followed by image5 (eg next) or image6 (eg cancel)

It's like you have different states where you look for different things and you can only move between the states in a certain order.

I created a little example for how you can use onEvent>.

In this simple case it looks for an image and when it finds it, clicks on it and moves to the next state and looks for another image, clicks on it until there has been 1 second since the last image found. (So if the same image shows up 20 times then it will click 20 times). After that it returns to the original state and continues looking for the original image again, and so on.

You need to adjust it for your situation but hopefully it illustrates the logic. Define the states and what to look for / action to take, and what state you want to move to next. You can easily add more onEvents, states and SRTs. Only the imagination limits what can be created.

Hope it helps.

Code: Select all

//Define array for States (1/0) active or not
ArrayDim>State,2
//Update States - Activate State 1
CODEBLOCK
    Let>State_1=1
    Let>State_2=0
ENDCODEBLOCK

//Define Events
CODEBLOCK
    OnEvent>CUSTOM,MyTriggerSub1,DoIT1,DoSomething1
    OnEvent>CUSTOM,MyTriggerSub2,DoIT2,DoSomething2
ENDCODEBLOCK

Label>Main
    Wait>0.1
Goto>Main

//SRT for Event 1
SRT>MyTriggerSub1
    If>State_1=1
        FindImagePos>%BMP_DIR%\......,SCREEN,0.7,1,XArr1,YArr1,NumFound1,CCOEFF
        If>NumFound1>0
            Timer>time0
            Let>DoIT1=TRUE
        Endif
    Endif
END>MyTriggerSub1
SRT>DoSomething1
  MouseMove>XArr1_0,YArr1_0
  LClick>
  Wait>0.2

  //Update States - Activate State 2
  CODEBLOCK
    Let>State_1=0
    Let>State_2=1
  ENDCODEBLOCK

  Let>DoIT1=FALSE
END>DoSomething1

//SRT for Event 2
SRT>MyTriggerSub2
    If>State_2=1
        FindImagePos>%BMP_DIR%\....,0.7,1,XArr2,YArr2,NumFound2,CCOEFF

        If>NumFound2>0
            Timer>time0
            Let>DoIT2=TRUE
        Else
            Timer>time1
            Let>TimeDiff={%time1%-%time0%}
            //Check if 1 sec has passed since last image found
            If>TimeDiff>1000

                //Update States - Activate State 1
                CODEBLOCK
                    Let>State_1=1
                    Let>State_2=0
                ENDCODEBLOCK
                Let>DoIT2=FALSE
            Endif
        Endif
    Endif
END>MyTriggerSub2
SRT>DoSomething2
  MouseMove>XArr2_0,YArr2_0
  LClick>
  Wait>0.2
END>DoSomething2

Tertium
Newbie
Posts: 5
Joined: Sun Aug 23, 2015 12:41 pm

Re: SRT Clicking

Post by Tertium » Tue Aug 25, 2015 6:50 pm

Thank you and if i could somehow add 1 more state to move btw in those lines it would be perfect since it moves between 3 states which are continue , cancel or finish.

And sometimes it gives an click thats off in a whole random place wonder why but in rest its perfect just gota fix that random click somehow

Update: Found that the off click is give by the continue image find hmmmm it dose not position the mouse over the image like it should but instead its positioned under the image

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