Help with ScrCmp() please Topic is solved
Help with ScrCmp() please
hi there,
i found a script written by skan:
ScrCmp() : Detects changes in screen by comparing two screenshots
viewtopic.php?f=6&t=82812
the function is if screen change detected, do something
and my question is, if want
change occurred --do nothing
no change for a while --do some thing
how to achieve this with this script
please give me some guidance, thanks in advance!
i found a script written by skan:
ScrCmp() : Detects changes in screen by comparing two screenshots
viewtopic.php?f=6&t=82812
the function is if screen change detected, do something
and my question is, if want
change occurred --do nothing
no change for a while --do some thing
how to achieve this with this script
please give me some guidance, thanks in advance!
Re: Help with ScrCmp() please
When you have a question about a post, you can always reply to the post itself.
One answer is below.
One answer is below.
Code: Select all
#Persistent
SetTimer, NoChange, -3000
If changed := ScrCmp(100, 100, 200, 200,, 1000, 200) {
SetTimer, NoChange, Off
MsgBox, Do nothing!
}
Return
NoChange:
A_Args.ScrCmp.Wait := False
MsgBox, Do some thing!
Return
Re: Help with ScrCmp() please
OK. I had not seen it earlier.
Re: Help with ScrCmp() please
sir, could you tell me how to keep watching selected area please
i combine your code and region selector and ScrCmp, it run once, then stop
cant figure it out...
Code: Select all
#Persistent
#NoEnv
#Warn
#SingleInstance, Force
SetBatchLines, -1
CoordMode, Mouse, Screen
InputRect(vX1, vY1, vX2, vY2)
vW := vX2-vX1, vH := vY2-vY1
if (vInputRectState = -1)
return
sleep, 200
SetTimer, NoChange, -3000
If changed := ScrCmp(vX1, vY1, vW, vH,, 1000, 200) {
SetTimer, NoChange, Off
msgbox,,, just keep watching, 1
}
Return
NoChange:
A_Args.ScrCmp.Wait := False
msgbox,,, gonna do some thing then keep watching, 1
Return
InputRect(ByRef vX1, ByRef vY1, ByRef vX2, ByRef vY2)
{
}
;==================================================
; Paste ScrCmp() below
ScrCmp( X, Y, W, H, Hwnd:=0x0, Sleep* )
{
}
Re: Help with ScrCmp() please
My first question is whether my script works when run as is, with no other changes. That will tell you whether you are starting with a working script.
Re: Help with ScrCmp() please
Ideas for you:
You can also fine-tune this by stopping and restarting the timer if needed at any point.
You now have the tools to adjust. The function waits for a change. In the meantime, the timer keeps running. You can add code to either section.
Code: Select all
SetTimer, NoChange, 3000
Loop {
changed := False
If changed := ScrCmp(100, 100, 200, 200,, 1000, 200)
Msgbox,,, just keep watching, 1
}
Return
NoChange:
If !changed
MsgBox,,, Gonna do some thing then keep watching, 1
Return
You now have the tools to adjust. The function waits for a change. In the meantime, the timer keeps running. You can add code to either section.
Re: Help with ScrCmp() please
sorry to bother you sir, i tested both kind of area with this code,mikeyww wrote: ↑02 Dec 2022, 07:39Ideas for you:
You can also fine-tune this by stopping and restarting the timer if needed at any point.Code: Select all
SetTimer, NoChange, 3000 Loop { changed := False If changed := ScrCmp(100, 100, 200, 200,, 1000, 200) Msgbox,,, just keep watching, 1 } Return NoChange: If !changed MsgBox,,, Gonna do some thing then keep watching, 1 Return
You now have the tools to adjust. The function waits for a change. In the meantime, the timer keeps running. You can add code to either section.
for a unchanged area, it popup "Gonna do some thing then keep watching" per 3 seconds, seems fine, but
for a constantly changing area, it popup both "just keep watching"/"Gonna do some thing then keep watching" alternatively, seems not right
Re: Help with ScrCmp() please Topic is solved
I already mentioned that you can stop and restart the timer.
You may need to tune this further.
EDIT: I removed the duplicate line.
Code: Select all
#SingleInstance Force
SoundBeep, 1500
Loop {
SetTimer, NoChange, 3000
ScrCmp(100, 100, 200, 200,, 250, 100)
SetTimer, NoChange, Off
Msgbox, 48, Changed, just keep watching, 2
}
NoChange:
MsgBox, 64, Unchanged, Gonna do some thing then keep watching, 2
Return
EDIT: I removed the duplicate line.
Re: Help with ScrCmp() please
the settimer reset trick looks right in logic, but it works not completely right,
i use it to keep watching an area which does changed about per 10 seconds,
but it still run nochange label no matter how much scrcmp delay or settimer period i set.
cant figure out why, so i modified some code, now it seems fine:
Code: Select all
SetTimer, isazero, % timeout
Loop {
MouseTip(x1, y1, width, height)
ScrCmp(x1, y1, width, height,, between, 200)
a++
Msgbox, , , % "a=" a, 2
}
isazero() {
if (a=0) {
try {
sendmail(ett)
}
} else a:=0
Msgbox, , , % "a=" a, 2
}
Re: Help with ScrCmp() please
This must be the part about the fine tuning....
Re: Help with ScrCmp() please
by now, seems there must be a msgbox after scrcmp statement,
or things goes wrong soon or later
through my tests, show the tooltip did not work, must be msgbox
still want to find a way could keep scrcmp works right and with less interrupt
Re: Help with ScrCmp() please
The timing is likely to matter.
My script disables the timer, but you have decided not to do that. This means that the timer in your script will continue to run.Sleep1 is duration (in ms) to wait between consecutive screen shots. When a screen change is detected, an additional screen shot is taken to confirm that change didn't occur because of a flicker. Sleep2 is duration (in ms) to wait between a regular screen shot and the additional confirmation screen shot.
Re: Help with ScrCmp() please
oh, now the question is, if the scrcmp statement does not followed by a msgbox command, i.e. totally background commandsmikeyww wrote: ↑07 Dec 2022, 05:32The timing is likely to matter.My script disables the timer, but you have decided not to do that. This means that the timer in your script will continue to run.Sleep1 is duration (in ms) to wait between consecutive screen shots. When a screen change is detected, an additional screen shot is taken to confirm that change didn't occur because of a flicker. Sleep2 is duration (in ms) to wait between a regular screen shot and the additional confirmation screen shot.
things will go wrong after a while inevitably, so i mean, your method or my method are both right on themselves
all i know is msgbox could avoid error occurs, maybe it is because of i run this script on a pc without monitor, till now i cant figure out why
Re: Help with ScrCmp() please
A timed cycle is repeated only after the previous cycle is completed. A MsgBox interrupts the cycle, because the script will not continue until the MsgBox is resolved.
Like I said, you need to fix the timing, and consider whether you want to disable the timer as well.
Like I said, you need to fix the timing, and consider whether you want to disable the timer as well.
Re: Help with ScrCmp() please
thanks for the reply, sirmikeyww wrote: ↑07 Dec 2022, 05:32The timing is likely to matter.My script disables the timer, but you have decided not to do that. This means that the timer in your script will continue to run.Sleep1 is duration (in ms) to wait between consecutive screen shots. When a screen change is detected, an additional screen shot is taken to confirm that change didn't occur because of a flicker. Sleep2 is duration (in ms) to wait between a regular screen shot and the additional confirmation screen shot.
sorry i didnt make it clear before
the thing like this,
if i dont leave a msgbox here
you code:
Code: Select all
Loop {
MouseTip(x1, y1, width, height)
SetTimer, NoChange, % timeout
ScrCmp(x1, y1, width, height,, between, 200)
SetTimer, NoChange, Off
;Msgbox, 48, Changed, just keep watching, 2
}
NoChange:
try {
no change thing
}
Code: Select all
SetTimer, isazero, % timeout
Loop {
MouseTip(x1, y1, width, height)
ScrCmp(x1, y1, width, height,, between, 200)
a++
;Msgbox, , , % "a=" a, 1
}
isazero() {
if (a=0) {
try {
no change thing
}
} else a:=0
}
then they start to do "no change thing" again and again which they should not to
(consider the specific area still keep changing), to adjust the timer couldnt work in this case
add the msgbox command back, the script back to normal, remove the msgbox command, things will go wrong after a while, no matter yours or mine, both couldnt work without msgbox
so i want to find a more silent way, maybe like replace the msgbox command with some background command if possible, unfortunately the tooltip couldnt work, dont know if there is another way could
Re: Help with ScrCmp() please
Since the MsgBox creates a two-second delay, you can try a sleep for that duration.
Re: Help with ScrCmp() please
tried, sadly still cant replace the msgbox
also try to replace msgbox command with the command below, consider the script run on a pc without monitor, nothing improved, strange
Code: Select all
SendMessage, 0x0112, 0xF170, 2,, Program Manager