Monday, January 15, 2018

sample 3&4 loop to find picture or pixel color

findpic(picpath,L:=100,Cx:=0,Cy:=0,Zx:=0,Zy:=0,P:=40)
{
ToolTip, %picpath%
SetTimer, RemoveToolTip, 5000

picpath=D:\script\%picpath%.bmp
;msgbox %picpath%
a:=0
loop
{
if L=0
break
else
L:=L-1
a:=a+1
;WinActivate , (Test)
if Zx <> 0
{
WinGetActiveStats, Title, Width, Height, X, Y
ImageSearch, FoundX, FoundY, Zx, Zy, Width, Height,*%P% %picpath%

;msgbox %Zx%,%Zy%,%Width%,%Height%,%ErrorLevel%
}
else
ImageSearch, FoundX, FoundY, Zx, Zy, A_ScreenWidth, A_ScreenHeight,*%P% %picpath%
if ErrorLevel = 0
{
if Cx <> 0
MouseClick,left ,Cx,Cy
else
{
GDIPToken := Gdip_Startup()                                       ; Start GDI Plus
pBM := Gdip_CreateBitmapFromFile( picpath ) ; Obtain GDI+ Handle
W:= Gdip_GetImageWidth( pBM ) ; Get Dimensions
H:= Gdip_GetImageHeight( pBM )
Gdip_DisposeImage( pBM )                                          ; Dispose image
Gdip_Shutdown( GDIPToken )                                        ; Shutdown GDI +
Cx:=FoundX+(W/2)+4
Cy:=FoundY+(H/2)+4
MouseClick,left ,Cx,Cy
}
mousemove,0,0
return 1
}
if L>1
sleep, 200
else
sleep, 300
}
return 0
}
return

pixclick(color,x,y,Cx:=0,Cy:=0,L=5,ck:=1)
{
;Blue Green Red
loop
{
PixelGetColor, color1, x, y ,RGB
color1:=substr(color1,3,99)
mousemove ,x, y
;msgbox %color% , %color1%
IfInString, color,%color1%
{
if Cx <> 0
{
x:=Cx
y:=Cy
}
sleep, 500
MouseClick,left ,x,y
mousemove,0,0
return 1
}
L:=L-1
if L=0
break
}
return 0
}



RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return