how to automatically run a script when an image loads on web
Best Answer Pulover , 18 July 2012 - 07:15 PM
; 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
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!
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!!
[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!
also the line <---- don't forget to....has some error
[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!
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!
..mm... 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 checknow the question is ..whether i can run another same type of script immediately after this one exitapps
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!
using simple commands
will talk tomorrow
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!