Page 1 of 1

Interrupted by questions about image search, please help me

Posted: 09 Apr 2015, 09:20
by autu
Interrupted by questions about image search, please help me see the code, thanks
My script is two cycles, if the first picture can not find the words, I can use the left mouse button to suspend the same token, the second picture can not find it, use the left mouse button can also be suspended.
My problem :when the script is runing, if two picture in the folder can not be found in webbrowers, then use the left mouse button to interrupt, then press and hold the left mouse button one time to be effective, if there is only a picture in the folder or not, then just click the left mouse button , I do not know what causes this condition (mouse serious delay)? How to solve
Script attached below:

F1::
loop
{
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Users\wang\Desktop\itt\1.bmp
If ErrorLevel = 0
MouseClick, left, 150, 235
break
}
if getkeystate("Lbutton",p)
break
}
loop
{
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Users\wang\Desktop\itt\2.bmp
If ErrorLevel = 0
{
x :=FoundX
y :=FoundY
xm :=x+125
ym :=y+30
MouseClick, left, 180, 520
Send 12345
break
}
if getkeystate("Lbutton",p)
break
}
return

Re: Interrupted by questions about image search, please help

Posted: 09 Apr 2015, 10:53
by autu
Cause: Search 1.bmp takes 1.5 seconds
What is the solution?

Re: Interrupted by questions about image search, please help

Posted: 09 Apr 2015, 17:21
by boiler
Your first loop will never actually loop. It will always break on the first pass through. Whether or not the MouseClick is executed, the break is always executed. You probably meant to include the break with the MouseClick, left, 150, 235 in a block of code. Put { } around those two statements if that's what you meant.

You also have an unmatched brace.

I find it a lot easier to follow the logic and to check for matching braces by indenting my code like this:

Code: Select all

F1::
	loop
	{
		ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Users\wang\Desktop\itt\1.bmp 
		If ErrorLevel = 0 
			MouseClick, left, 150, 235 ; <<< This will only get executed if ErrorLevel = 0
		break ; <<< This will always be executed, causing the loop to only be executed once
	}
	if getkeystate("Lbutton",p)
		break
	} ; <<<<< THIS IS AN UNMATCHED BRACE
	loop
	{
		ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Users\wang\Desktop\itt\2.bmp 
		If ErrorLevel = 0 
		{ 
			x :=FoundX
			y :=FoundY 
			xm :=x+125
			ym :=y+30
			MouseClick, left, 180, 520 
			Send 12345 
			break 
		}
		if getkeystate("Lbutton",p) 
			break
	}
return

Re: Interrupted by questions about image search, please help

Posted: 09 Apr 2015, 20:46
by autu
Thank you very much