Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

how to automatically run a script when an image loads on web



  • Please log in to reply
64 replies to this topic
smorgasboard
  • Members
  • 660 posts
  • Last active: Jan 14 2016 08:53 AM
  • Joined: 18 Jul 2012
it is exactly the same...as u gave me..

; This script was created using Pulover's Macro Creator

#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines, -1
CoordMode, Pixel, Screen

; Make a ScreenShot with the image and place it in the same directory of the script.
ImageFile1 := "ScreenShot1.png" ; Name of the image file from screenshot.
ImageFile2 := "ScreenShot2.png" ; Name of the image file from screenshot.

F2:: ; Toggles search timer on/off
SetTimer, SearchImage1, % If (k := !k) ? 100 : "off"
SetTimer, SearchImage2, % If (k := !k) ? 100 : "off"
TrayTip,, % If (t := !t) ? "On" : "Off"
return

SearchImage1:
ImageSearch, FoundX, FoundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, %ImageFile1%
If ErrorLevel = 0 ; Put your code inside the braces below.
{
MsgBox, 49, Continue?, Image / Pixel Found at %FoundX%x%FoundY%.`nPress OK to continue.
IfMsgBox, Cancel
{
SetTimer, SearchImage1, off
TrayTip,, Off
}
}
return <--- DON'T FORGET TO USE RETURN BEFORE THE NEXT LABEL!

SearchImage2:
ImageSearch, FoundX, FoundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, %ImageFile2%
If ErrorLevel = 0 ; Put your code inside the braces below.
{
MsgBox, 49, Continue?, Image / Pixel Found at %FoundX%x%FoundY%.`nPress OK to continue.
IfMsgBox, Cancel
{
SetTimer, SearchImage2, off
TrayTip,, Off
}
}
return

Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
I know, but it's a template. I thought you had modified to your own commands...
You need to give me more details so I can understand the situation better.
This line is what stops the image search: SetTimer, SearchImage2, off... you can add commands before or add a condition to execute it, but I don't know what you are doing when the image is found.

Btw, please use tags when you post code, ok? Just paste the code inside it.

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


smorgasboard
  • Members
  • 660 posts
  • Last active: Jan 14 2016 08:53 AM
  • Joined: 18 Jul 2012
sir i m sending tabs , enter, some key strokes, some mouse clicks, when the image is loaded
as i m new...so didn't know how to paste codes..

sir if the 2nd image reappears can i execute a different set of codes!!

Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
To paste code click the Post Reply or Full Editor button and click the "Code" button, then just paste the code inside like this:
[color=#FF0000][code][/color]ImageFile1 := "ScreenShot1.png" ; Name of the image file from screenshot.
ImageFile2 := "ScreenShot2.png" ; Name of the image file from screenshot.[color=#FF0000][/code][/color]
Ok, I suggest you creating a third Timer with the same file to execute after the second is found:
[color=#008000]; This script was created using Pulover's Macro Creator[/color]

#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines, -1
CoordMode, Pixel, Screen

[color=#008000]; Make a ScreenShot with the image and place it in the same directory of the script.[/color]
[color=#FF0000]ImageFile1[/color] := "ScreenShot1.png" ; Name of the image file from screenshot.
[color=#0000FF]ImageFile2[/color] := "ScreenShot2.png" ; Name of the image file from screenshot.

F2:: [color=#008000]; Toggles search timer on/off[/color]
SetTimer, [color=#FF0000]SearchImage1[/color], % If (k := !k) ? 100 : "off"
SetTimer, [color=#0000FF]SearchImage2[/color], % If (k := !k) ? 100 : "off"
TrayTip,, % If (t := !t) ? "On" : "Off"
return

[color=#FF0000]SearchImage1:
ImageSearch, FoundX, FoundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, %ImageFile1%
If ErrorLevel = 0 [color=#008000] ; Put your code inside the braces below.[/color]
{
MsgBox, 49, Continue?, Image / Pixel Found at %FoundX%x%FoundY%.`nPress OK to continue.
IfMsgBox, Cancel
{
SetTimer, [color=#4000FF]SearchImage1, off[/color]
TrayTip,, Off
}
}
return [color=#8000FF]<--- DON'T FORGET TO USE RETURN BEFORE THE NEXT LABEL![/color]
[/color]
[color=#0000FF]SearchImage2:
ImageSearch, FoundX, FoundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, %ImageFile2%
If ErrorLevel = 0 [color=#008000] ; Put your code inside the braces below.[/color]
{
MsgBox, 49, Continue?, Image / Pixel Found at %FoundX%x%FoundY%.`nPress OK to continue.
IfMsgBox, Cancel
{
SetTimer, [color=#4000FF]SearchImage2, off[/color]
TrayTip,, Off
SetTimer, [color=#8000FF]SearchImage3[/color], 100
}
}
return[/color]

[color=#FF8000]SearchImage3:
ImageSearch, FoundX, FoundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, %ImageFile2%
If ErrorLevel = 0 [color=#008000] ; This will be the new set of actions.[/color]
{
MsgBox, 49, Continue?, Image / Pixel Found at %FoundX%x%FoundY%.`nPress OK to continue.
IfMsgBox, Cancel
{
SetTimer, [color=#4000FF]SearchImage3, off[/color]
TrayTip,, Off
}
}
return[/color]

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


smorgasboard
  • Members
  • 660 posts
  • Last active: Jan 14 2016 08:53 AM
  • Joined: 18 Jul 2012
one min..sir jst checking

smorgasboard
  • Members
  • 660 posts
  • Last active: Jan 14 2016 08:53 AM
  • Joined: 18 Jul 2012
it seems to take time...will reply after trying

smorgasboard
  • Members
  • 660 posts
  • Last active: Jan 14 2016 08:53 AM
  • Joined: 18 Jul 2012
sir ..the codes to be executed after the 2nd image appears for the first time is not running...something is wrong...
also the line <---- don't forget to....has some error

smorgasboard
  • Members
  • 660 posts
  • Last active: Jan 14 2016 08:53 AM
  • Joined: 18 Jul 2012
now even if after pressing f2 to switch the script off...it runs!!...something is wrong this time sir

Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
[color=#008000]; This script was created using Pulover's Macro Creator[/color]



#NoEnv

SetWorkingDir %A_ScriptDir%

SetBatchLines, -1

CoordMode, Pixel, Screen



[color=#008000]; Make a ScreenShot with the image and place it in the same directory of the script.[/color]

[color=#FF0000]ImageFile1[/color] := "ScreenShot1.png" ; Name of the image file from screenshot.

[color=#0000FF]ImageFile2[/color] := "ScreenShot2.png" ; Name of the image file from screenshot.



F2:: [color=#008000]; Toggles search timer on/off[/color]

SetTimer, [color=#FF0000]SearchImage1[/color], % If (k := !k) ? 100 : "off"

SetTimer, [color=#0000FF]SearchImage2[/color], % If (k := !k) ? 100 : "off"

SetTimer, [color=#FF8000]SearchImage3[/color], % If (k := !k) ? "off" : "off"

TrayTip,, % If (t := !t) ? "On" : "Off"

return



[color=#FF0000]SearchImage1:

ImageSearch, FoundX, FoundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, %ImageFile1%

If ErrorLevel = 0 [color=#008000] ; Put your code inside the braces below.[/color]

{

MsgBox, 49, Continue?, Image / Pixel Found at %FoundX%x%FoundY%.`nPress OK to continue.

IfMsgBox, Cancel

{

SetTimer, [color=#4000FF]SearchImage1, off[/color]

TrayTip,, Off

}

}

return



[color=#0000FF]SearchImage2:

ImageSearch, FoundX, FoundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, %ImageFile2%

If ErrorLevel = 0 [color=#008000] ; Put your code inside the braces below.[/color]

{

MsgBox, 49, Continue?, Image / Pixel Found at %FoundX%x%FoundY%.`nPress OK to continue.

IfMsgBox, Cancel

{

SetTimer, [color=#4000FF]SearchImage2, off[/color]

TrayTip,, Off

SetTimer, [color=#8000FF]SearchImage3[/color], 100

}

}

return[/color][/color]



[color=#FF8000]SearchImage3:

ImageSearch, FoundX, FoundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, %ImageFile2%

If ErrorLevel = 0 [color=#008000] ; This will be the new set of actions.[/color]

{

MsgBox, 49, Continue?, Image / Pixel Found at %FoundX%x%FoundY%.`nPress OK to continue.

IfMsgBox, Cancel

{

SetTimer, [color=#4000FF]SearchImage3, off[/color]

TrayTip,, Off

}

}

return[/color]

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


smorgasboard
  • Members
  • 660 posts
  • Last active: Jan 14 2016 08:53 AM
  • Joined: 18 Jul 2012
..mm....this new thing which want i not working fine..so is there a way by which i can stop the ahk script in itself....or/and ..i direct the same script to run another ahk script

Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
You can assign hotkeys to commands like Reload and ExitApp. To run a different script you can use the Run command.

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


smorgasboard
  • Members
  • 660 posts
  • Last active: Jan 14 2016 08:53 AM
  • Joined: 18 Jul 2012
exitapp has done wonders ..but to make it work i had to put it immediately after my second code..

..mm... now the question is ..whether i can run another same type of script immediately after this one exitapps

Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012

now the question is ..whether i can run another same type of script immediately after this one exitapps

It would have to before it... or you can check OnExit label.

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


smorgasboard
  • Members
  • 660 posts
  • Last active: Jan 14 2016 08:53 AM
  • Joined: 18 Jul 2012
sir i found an easy roundabout way

using simple commands

will talk tomorrow

Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
Good to know, sir!
You know, I think that one of the best ways to learn how to do something in scripts is looking at other people's work. You can learn many things searching the forums and just copying and executing scripts you find that may be close to what you want.

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!