Jump to content
feistcomputers

Imagesearch ? CCleaner

Recommended Posts

feistcomputers

I have be working on this stuff since april on my own and i'm about ready to call it quits.  It should be possible to do.  If your good at scripting.  I'm getting better but need some help.  I can get the clicks to work but not the timer. Want to save as much time as i can. so instead of a timer that goes way over what is needed to run the scan or scans, i want to apply this to many programs i use for computer cleanups in my shop.  Can't get it to click next button when button becomes active again.  any help much appreciated. Here is my code. The closing of the browsers isnt working muchless the image detection. Maybe its not getting to it. would be nice if it would show you where it go stuck.  thankyou.

#RequireAdmin

;Gives you admin rights
; By doing this you can have folder anywhere just as long as exe is in same folder as script.
Run(@ScriptDir & '\CCleaner.exe')
; Always use this, it does mapping using the window versus the the whole screen, because every computer can have diff. resolutions.
; have to change it in the info getter too. options/coordmode/windows
AutoItSetOption('MouseCoordMode', 0)


While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
    Sleep(100)
WEnd
While ProcessExists("safari.exe")
    ProcessClose("safari.exe")
    Sleep(100)
WEnd
While ProcessExists("microsoftedge.exe")
    ProcessClose("microsoftedge.exe")
    Sleep(100)
WEnd
While ProcessExists("firefox.exe")
    ProcessClose("firefox.exe")
    Sleep(100)
WEnd
While ProcessExists("chrome.exe")
    ProcessClose("chrome.exe")
    Sleep(100)
WEnd

;Waits for our window to come up
WinWait("Piriform CCleaner")
;When it see's it the windows gets activated right away.
WinActivate("Piriform CCleaner")
Sleep(900)
;primary means left click mouse, secondary means to right click. coord for where button is from info from mouse tab on into tool. 1 means 1 click.
MouseClick('primary', 727, 530, 1, 0)


#include <ImageSearch.au3>
HotKeySet("p", "checkForImage")
global $y = 0, $x = 0
Func checkForImage()
Local $search = _ImageSearch('checkImage.bmp', 0, $x, $y, 0)
If $search = 1 Then
MouseMove($x, $y, 10)
EndIf
EndFunc
while 1
sleep(200)
WEnd



WinWait("Piriform CCleaner")
;When it see's it the windows gets activated right away.
WinActivate("Piriform CCleaner")
Sleep(300)
;Application tab click.
MouseClick('primary', 523, 151, 1, 0)

Sleep(3000)
MouseClick('primary', 275, 114, 1, 0)
Sleep(344)
WinWait("Piriform CCleaner")
;When it see's it the windows gets activated right away.
WinActivate("Piriform CCleaner")
MouseClick('primary', 716, 521, 1, 0)
Sleep(3000)
;goto reg
Send("!g")
;scan reg
Send('!s')
Sleep(3000)
Send('!f')
MouseClick('primary', 565, 520, 1, 0)
;scan reg
Send('!s')
Sleep(2000)
Send('!f')
MouseClick('primary', 565, 520, 1, 0)
WinClose

 

Share this post


Link to post
Share on other sites
JohnOne

Well for a start you have no error checking or debugging lines such as ConsoleWrite or MsgBox to indicate where you are in your script and what is failing.

You could add this to top of script to begin with.

Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info

Then when you hover mouse over tray Icon, it will show in a tooltip what file and code line your script is at.

  • Like 1

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
JLogan3o13

@Bert you look to be correct :>

Been a customer so long I forgot they don't support everything for the free version.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
kylomas

This works for me using the free version...

shellexecute("c:\program files\ccleaner\ccleaner.exe ","/auto")

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
feistcomputers

I have used the auto and only goes like seven seconds. Much to quick, and in my mind since i can not see it i feel i'm not doing a good job on the cleanup. Once i get this time figured out it will spill over into all my tools i would like to automate. I just cant get past this. And i have like 5 other programs i want to do but dont want to move on until i finish this. So without using the command line i want to get this functioning with autoit. If there is a tutorial to watch please point me in the direction.  I've tried different scripts but either i scripting it wrong  or ccleaner is a bit tuff. what info would you guys need to help me figure this out :)

Share this post


Link to post
Share on other sites
feistcomputers

I had found that script rummaging thru the forums.  2yrs old. How would i fix it.

 

Now i'm blessed with errors. download beta config file to editor.  Not sure if that is the answer or not. Didnt work.      uuuugggggg

Capture.JPG

Edited by feistcomputers

Share this post


Link to post
Share on other sites
JLogan3o13

@feistcomputers,  if you want people to help you with code, please post code or link to where you found it. Posting a picture does not give us everything needed to help; worse, it forces someone trying to help you to type all the code out manually.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
feistcomputers

I think I got some of it. It seemed to click first but then goto registry tab and sit but i hadn't really got that far before.  So I redid and hopefully fixed them all. But now it says.  

"D:\Shop-Server-Share\FC Scripts\CCleanerAuto\CCleaner.au3" (66) : ==> Duplicate function name.:
Func checkForImage()

Not sure tried to give same image a copy with diff name.  Not sure what its telling me or if rest of the script works.  Here it is.

Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info
#RequireAdmin

;Give you admin rights
; By doing this you can have folder anywhere just as long as exe is in same folder as script.
Run(@ScriptDir & '\CCleaner.exe')
; Always use this, it does mapping using the window versus the the whole screen, because every computer can have diff. resolutions.
; have to change it in the info getter too. options/coordmode/windows
AutoItSetOption('MouseCoordMode', 0)


While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
    Sleep(100)
WEnd
While ProcessExists("safari.exe")
    ProcessClose("safari.exe")
    Sleep(100)
WEnd
While ProcessExists("microsoftedge.exe")
    ProcessClose("microsoftedge.exe")
    Sleep(100)
WEnd
While ProcessExists("firefox.exe")
    ProcessClose("firefox.exe")
    Sleep(100)
WEnd
While ProcessExists("chrome.exe")
    ProcessClose("chrome.exe")
    Sleep(100)
WEnd

;Waits for our window to come up
WinWait("Piriform CCleaner")
;When it see's it the windows gets activated right away.
WinActivate("Piriform CCleaner")
Sleep(3000)
;Clicking In Cleaner/Windows Tab, Run Cleaner button.
MouseClick('primary', 727, 530, 1, 0)

;waits for Run Cleaner button to become blue & active again.
#include <ImageSearch.au3>
HotKeySet("p", "checkForImage")
global $y = 0, $x = 0
Func checkForImage()
Local $search = _ImageSearch('checkImage.bmp', 0, $x, $y, 0)
If $search = 1 Then
MouseMove($x, $y, 10)
EndIf
EndFunc


WinWait("Piriform CCleaner")
;When it see's it the windows gets activated right away.
WinActivate("Piriform CCleaner")
Sleep(300)
;Application tab click.
MouseClick('primary', 279,109, 1, 0)
Sleep(3000)
;Clicking In Cleaner/Applications Tab, Run Cleaner button.
MouseClick('primary', 727, 530, 1, 0)

#include <ImageSearch.au3>
HotKeySet("p", "checkForImage")
global $y = 0, $x = 0
Func checkForImage()
Local $search = _ImageSearch('checkImage1.bmp', 0, $x, $y, 0)
If $search = 1 Then
MouseMove($x, $y, 10)
EndIf
EndFunc


;goto registry Tab
Send("!g")
;Push button "scan for issues" 1st scan of 2
Send('!s')

;waits for "Fix selected issues" button to become blue & active
#include <ImageSearch.au3>
HotKeySet("p", "checkForImage")
global $y = 0, $x = 0
Func checkForImage()
Local $search = _ImageSearch('fix.bmp', 0, $x, $y, 0)
If $search = 1 Then
MouseMove($x, $y, 10)
EndIf
EndFunc

;fix registry errors button
Send('!f')
Sleep(5000)
;Close button after fix
MouseClick('primary', 239, 226, 1, 0)

;Push button "scan for issues" 2nd scan of 2
Send('!s')
Sleep(2000)

;waits for "Fix selected issues" button to become blue & active
#include <ImageSearch.au3>
HotKeySet("p", "checkForImage")
global $y = 0, $x = 0
Func checkForImage()
Local $search = _ImageSearch('fix.bmp', 0, $x, $y, 0)
If $search = 1 Then
MouseMove($x, $y, 10)
EndIf
EndFunc

;fix registry errors button
Send('!f')
Sleep(5000)
;Close button after fix
MouseClick('primary', 239, 226, 1, 0)

WinClose

while 1
sleep(200)
WEnd

 

Share this post


Link to post
Share on other sites
feistcomputers

Hey John, I'm confused.  I though you would have to put 

;waits for Run Cleaner button to become blue & active again.
#include <ImageSearch.au3>
HotKeySet("p", "checkForImage")
global $y = 0, $x = 0
Func checkForImage()
Local $search = _ImageSearch('checkImage.bmp', 0, $x, $y, 0)
If $search = 1 Then
MouseMove($x, $y, 10)
EndIf
EndFunc

every time you wanted to search for a picture or new picture. Is this not correct.  I want to thank you all to for helping me.  I have spent so much time trying to get this to work since april.  Doing it to save time, so i can start a virus removal and let it go.  Spend more time with my kids instead of working on computers til after they go to bed.  

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • tiye0405
      By tiye0405
      Hello,
      global $y, $x #RequireAdmin Global $Paused HotKeySet("{NUMPAD2}", "Pause") HotKeySet("{NUMPAD8}", "End") Opt("MouseClickDownDelay", 30) #include <ImageSearch2015.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <UpDownConstants.au3> #include <Misc.au3> Sleep(6000) Sleep(3000) $search1 = _WaitForImageSearch("goo.bmp", 30, 1, $x, $y, 10) If $search1 = 1 Then MouseMove(1500, 1500, 10) Sleep(100) MouseClick("right") Sleep(300) EndIf I've this script.
      The problem is that it work the way it is supposed to but doesnt work on a friends pc, even tho we have the same image search in C/programms(x86)/autoit3/include 
      and the same dll in system 32.
      When he starts the script on the desktop without having the "goo.bmp" file on his pc, the script finds it and right clicks the given location, while for me it doesnt and i have to open the folder with the "goo.bmp" picture in it.

      Im out of ideas on what could cause the problem.
      Any help?
      Thank you in advance
       
       
    • Atoxis
      By Atoxis
      Howdy, I've gone through a lot of au3 forums, and I once had a working Imagesearch script that I got from here.  However, and i'm just totally not sure how but my imagesearch scripts aren't working anymore.
      I'm not new to au3 but i'm not the most experienced with it's syntax/commands.

      Anyways, I've looked over the big threads involving imagesearch.

      Does anyone have a working Imagesearch x64 for win10 that is currently working as of the date with the post.

      Dll's and what not is fine, just when I tell the script to run, I want to be able to find the image on the screen!
      Can't find a working copy so if anyone has one please send it my way lol.

      I've taken all the imagesearch downloads and what not and have played with them but I can't get any of them working on my end, despite others saying they're working.
      Thanks.
    • PoojaKrishna
      By PoojaKrishna
      I have developed a script to find multiple or all occurrence of an image from desktop using the ImageSearch UDF. Please note that the resulting array has the starting position of the images, not middle.
      #include-once #include <Array.Au3> #RequireAdmin #AutoIt3Wrapper_UseX64=Y Global $y = 0, $x = 0 ;Result x and y coordinates Dim $aResult[1] ;Resulting array Global $sImagePath = @ScriptDir &"\Rect.bmp" Global $nImageWidth = 0 ;Image width Global $nImageHeight = 0 ;Image Height _ImageSearchMultiple() Func _ImageSearchMultiple() Local $search = _ImageSearch($sImagePath, 0, $x, $y, 10) If $search = 1 Then _ArrayDisplay($aResult) Else Msgbox(0,"Not Found","Image Not Found") EndIf EndFunc ; ------------------------------------------------------------------------------ ; ; AutoIt Version: 3.0 ; Language: English ; Description: Functions that assist with Image Search ; Require that the ImageSearchDLL.dll be loadable ; ; ------------------------------------------------------------------------------ ;=============================================================================== ; ; Description: Find the position of an image on the desktop ; Syntax: _ImageSearchArea, _ImageSearch ; Parameter(s): ; $findImage - the image to locate on the desktop ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; ; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify ; a desktop region to search ; ;=============================================================================== Func _ImageSearch($findImage,$resultPosition, ByRef $x, ByRef $y,$tolerance, $HBMP=0) $nStartX = 0 $nStartY = 0 $nMaxX = @DesktopWidth $nMaxY = @DesktopHeight $nEndX = $nMaxX $nEndY = $nMaxY $nCount = 0 $aResult[0] = $nCount ; Count $nImageWidth = 0 $nImageHeight = 0 While (1) $nResult = _ImageSearchArea($findImage,$resultPosition,$nStartx,$nStarty,$nEndX,$nEndY,$x,$y,$tolerance,$HBMP) If $nResult = 1 Then $nCount = $nCount + 1 $aResult[0] = $nCount Redim $aResult[$nCount + 1 ] $aResult[$nCount] = $x & "," & $y $nStartX = $x + $nImageWidth $nStartY = $y $nEndX = $nMaxX $nEndY = $y + $nImageHeight If $nStartX + $nImageWidth > $nMaxX Or $nStartY + $nImageHeight > $nMaxY Then $nStartX = 0 $nStartY = $y + 1 $nEndX = $nMaxX $nEndY = $nMaxY ContinueLoop EndIf Else If $nEndY >= $nMaxY Then ExitLoop Else $nStartX = 0 $nStartY = $Y + 1 $nEndX = $nMaxX $nEndY = $nMaxY EndIf EndIf wend If $aResult[0] = 0 Then Return 0 Else Return 1 EndIf EndFunc Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom, ByRef $x, ByRef $y, $tolerance,$HBMP=0) ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom) if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage If IsString($findImage) Then $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP) Else $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"ptr",$findImage,"ptr",$HBMP) EndIf If IsArray( $result ) = 0 Then return 0 ; If error exit if $result[0]="0" then return 0 ; Otherwise get the x,y location of the match and the size of the image to ; compute the centre of search $array = StringSplit($result[0],"|") $x=Int(Number($array[2])) $y=Int(Number($array[3])) If $nImageWidth = 0 Then $nImageWidth = Int(Number($array[4])) $nImageHeight = Int(Number($array[5])) EndIf if $resultPosition=1 then $x=$x + Int(Number($array[4])/2) $y=$y + Int(Number($array[5])/2) endif return 1 EndFunc ;=============================================================================== ; ; Description: Wait for a specified number of seconds for an image to appear ; ; Syntax: _WaitForImageSearch, _WaitForImagesSearch ; Parameter(s): ; $waitSecs - seconds to try and find the image ; $findImage - the image to locate on the desktop ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; ; ;=============================================================================== Func _WaitForImageSearch($findImage,$waitSecs,$resultPosition, ByRef $x, ByRef $y,$tolerance,$HBMP=0) $waitSecs = $waitSecs * 1000 $startTime=TimerInit() While TimerDiff($startTime) < $waitSecs sleep(100) $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance,$HBMP) if $result > 0 Then return 1 EndIf WEnd return 0 EndFunc ;=============================================================================== ; ; Description: Wait for a specified number of seconds for any of a set of ; images to appear ; ; Syntax: _WaitForImagesSearch ; Parameter(s): ; $waitSecs - seconds to try and find the image ; $findImage - the ARRAY of images to locate on the desktop ; - ARRAY[0] is set to the number of images to loop through ; ARRAY[1] is the first image ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns the index of the successful find ; On Failure - Returns 0 ; ; ;=============================================================================== Func _WaitForImagesSearch($findImage,$waitSecs,$resultPosition, ByRef $x, ByRef $y,$tolerance,$HBMP=0) $waitSecs = $waitSecs * 1000 $startTime=TimerInit() While TimerDiff($startTime) < $waitSecs for $i = 1 to $findImage[0] sleep(100) $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance,$HBMP) if $result > 0 Then return $i EndIf Next WEnd return 0 EndFunc Func _ImageSize($sFileName) Local $aRet[2], $sExt = StringRegExpReplace($sFileName, "^.*\.", "") If (FileExists($sFileName) = 0) Or _ ((StringLen($sExt) = 3) And (StringRegExp($sExt, "(?i)(bmp|gif|jpg|png|tif|emf|wmf)") = 0)) Or _ ((StringLen($sExt) = 4) And (StringRegExp($sExt, "(?i)(tiff|jpeg)") = 0)) Then _ Return SetError(1, 0, $aRet) Local $ghGDIPDll = DllOpen("GDIPlus.dll") Local $tInput = DllStructCreate("int Version;ptr Callback;int NoThread;int NoCodecs") Local $tToken = DllStructCreate("ulong_ptr Data") DllStructSetData($tInput, "Version", 1) DllCall($ghGDIPDll, "int", "GdiplusStartup", "ptr", DllStructGetPtr($tToken), "ptr", DllStructGetPtr($tInput), "ptr", 0) Local $aImage = DllCall($ghGDIPDll, "int", "GdipLoadImageFromFile", "wstr", $sFileName, "ptr*", 0) Local $aResult = DllCall($ghGDIPDll, "int", "GdipGetImageWidth", "handle", $aImage[2], "uint*", -1) $aRet[0] = $aResult[2] $aResult = DllCall($ghGDIPDll, "int", "GdipGetImageHeight", "handle", $aImage[2], "uint*", 0) $aRet[1] = $aResult[2] DllCall($ghGDIPDll, "int", "GdipDisposeImage", "handle", $aImage[2]) DllCall($ghGDIPDll, "none", "GdiplusShutdown", "ptr", DllStructGetData($tToken, "Data")) DllClose($ghGDIPDll) Return SetError(0, 0, $aRet) EndFunc ;==>_ImageSize I'm also attaching the code to capture the image , written by Melba23.
      #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #Include <ScreenCapture.au3> #Include <Misc.au3> #include <WinAPISysWin.au3> #include <File.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #Include <ScreenCapture.au3> #Include <Misc.au3> #include <WinAPISysWin.au3> Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $sBMP_Path Mark_Rect() Func Mark_Rect() Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp Local $UserDLL = DllOpen("user32.dll") ; Create transparent GUI with Cross cursor $hCross_GUI = GUICreate("Test", @DesktopWidth, @DesktopHeight - 20, 0, 0, $WS_POPUP, $WS_EX_TOPMOST) WinSetTrans($hCross_GUI, "", 8) GUISetState(@SW_SHOW, $hCross_GUI) GUISetCursor(3, 1, $hCross_GUI) Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) GUISetBkColor(0x000000) ; Wait until mouse button pressed While Not _IsPressed("01", $UserDLL) Sleep(10) WEnd ; Get first mouse position $aMouse_Pos = MouseGetPos() $iX1 = $aMouse_Pos[0] $iY1 = $aMouse_Pos[1] ; Draw rectangle while mouse button pressed While _IsPressed("01", $UserDLL) $aMouse_Pos = MouseGetPos() $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0) $hMask = _WinAPI_CreateRectRgn($iX1, $aMouse_Pos[1], $aMouse_Pos[0], $aMouse_Pos[1] + 1) ; Bottom of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1]) ; Left of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1) ; Top of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($aMouse_Pos[0], $iY1, $aMouse_Pos[0] + 1, $aMouse_Pos[1]) ; Right of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) ; Set overall region _WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask) If WinGetState($hRectangle_GUI) < 15 Then GUISetState() Sleep(10) WEnd ; Get second mouse position $iX2 = $aMouse_Pos[0] $iY2 = $aMouse_Pos[1] ; Set in correct order if required If $iX2 < $iX1 Then $iTemp = $iX1 $iX1 = $iX2 $iX2 = $iTemp EndIf If $iY2 < $iY1 Then $iTemp = $iY1 $iY1 = $iY2 $iY2 = $iTemp EndIf GUIDelete($hRectangle_GUI) GUIDelete($hCross_GUI) DllClose($UserDLL) $sBMP_Path = @ScriptDir & "\Rect.bmp" _ScreenCapture_Capture($sBMP_Path, $iX1, $iY1, $iX2, $iY2, False) EndFunc ;==>Mark_Rect Please see the following links to see the original posts on the ImageSearch UDF and the usage.
      I hope it will help someone here.
       
    • tiye0405
      By tiye0405
      Hello, 
       
      I currently have a problem that deals with moving the mouse to a given location + or - a certain distance.
      $search1 =_WaitForImageSearch("envelope.bmp", 10, 1, $x, $y, 20)
      $search2 =_WaitForImageSearch("envelope2.bmp", 10, 1, $x, $y, 20)
       
      If $search1 = 1 Then
                  Sleep(100)
                  MouseMove($x, $y, 10)
                  sleep(99)
                  MouseClick("left")
                 Sleep(99)
      ElseIf $search2 = 1 Then
                 Sleep(100)
                 MouseMove($x, $y2, 10)
                 sleep(99)
                 MouseClick("left")
                 Sleep(100)
      Else
                Sleep(150)
                MouseMove($x2, $y, 10)
                Sleep(150)
                MouseClick("left")
               Sleep(150)
      EndIf
      The problem about this is that i defined $x2 = $x - 175  and $y2 = $y + 35
      I got these numbers ( 175 and 35) with the autoit helper and just subtracted point where it is to the point its supposed to move but it doesnt work.

      is there any proper way to find the distance between 2 points in pixels?
       
      Imgsearch doesnt always work for this picture so i want it to have a backup
       
      edit: could it be that the definition of $x and $y  from the previous image search arent there anymore and thats why it moves my mouse to strange places? 
      is there a way to preserve the $x $y from the previous img search untill the next succesful one?
       
       
    • Miliardsto
      By Miliardsto
      Hello im using Imagesearc function and almost always it works great but i have seen on 2 computers this function not works. I dont know why and cant figure out whats going on.
       
      So there are windows 8 64bit and 10 64bit.
      I use script like below so in program folder I got there 4 files
      ImageSearchDLLx32 ImageSearchDLLx64 msvcr110 msvcr110d And it should work I think, it would chose proper file to windows and use it.
      Should I copy Imagesearch to windows directory or system32 directory too or if it is on program folder it is enough?
      I have tried other imagesearch dll and with no success.
      Tried change resolution, colors, some graphic settings etc and no effect
       
      Maybe someone know what can causing problem with functionality imagesearch function?
      And where I should finally put imagesearch dll file to be sure it would be loaded correctly?
       
      There are these 4 files
      https://mega.nz/#!GkMUFSoC!ND0HlpWGZYywxMEF7Nan5YOUdBUPPBE7VAd0TM1Lhm8
       
       
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=x64.Exe #AutoIt3Wrapper_Outfile_x64=x32.Exe #AutoIt3Wrapper_Compile_Both=y #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include-once #include <WinAPIFiles.au3> ; for _WinAPI_Wow64EnableWow64FsRedirection #include <ScreenCapture.au3> ;_ScreenCapture_CaptureWnd etc. ;using this in the example to create a test image, otherwise not neccessary here #include <ButtonConstants.au3> #include <MsgBoxConstants.au3> Local $h_ImageSearchDLL = -1; Will become Handle returned by DllOpen() that will be referenced in the _ImageSearchRegion() function #include <ImageSearchUDF.au3> #Region When running compiled script, Install needed DLLs if they don't exist yet If Not FileExists("ImageSearchDLLx32.dll") Then FileInstall("ImageSearchDLLx32.dll", "ImageSearchDLLx32.dll", 1);FileInstall ( "source", "dest" [, flag = 0] ) If Not FileExists("ImageSearchDLLx64.dll") Then FileInstall("ImageSearchDLLx64.dll", "ImageSearchDLLx64.dll", 1) If Not FileExists("msvcr110d.dll") Then FileInstall("msvcr110d.dll", "msvcr110d.dll", 1);Microsoft Visual C++ Redistributable dll x64 If Not FileExists("msvcr110.dll") Then FileInstall("msvcr110.dll", "msvcr110.dll", 1);Microsoft Visual C++ Redistributable dll x32 #EndRegion HotKeySet("h", "search") Global $x = 0, $y = 0 Func search() Local $img = _ImageSearch('img.bmp', 0, $x, $y, 0) If $img = 1 Then MsgBox("", "", "FOUND IMAGE") Else MsgBox("", "", "NOT FOUND IMAGE") EndIf EndFunc While 1 sleep(200) WEnd #Region TESTING/Example Local $bTesting = False; Change to TRUE to turn on testing/example If $bTesting Then cr(">" & "_ImageSearchStartup()=" & _ImageSearchStartup(), 2) OnAutoItExitRegister(_ImageSearchShutdown) cr("!Testing...") ;using Notepad as a simple example #Region Notepad Snapshot Creation $hWin = WinGetHandle("[CLASS:Notepad]") If Not IsHWnd($hWin) Then If Run("notepad.exe") = 0 Then cr("Couldn't run notepad.exe") Local $hWin = WinWait("[CLASS:Notepad]", "", 10) If $hWin = 0 Then cr("Notepad WinWait Timeout!") EndIf WinSetState($hWin, "", @SW_RESTORE) WinSetState($hWin, "", @SW_SHOW) WinActivate($hWin) Local $testimage = "24bit.bmp" _ScreenCapture_CaptureWnd($testimage, $hWin, 0, 0, -1, -1, False);_ScreenCapture_CaptureWnd ( $sFileName, $hWnd [, $iLeft = 0 [, $iTop = 0 [, $iRight = -1 [, $iBottom = -1 [, $bCursor = True]]]]] ) cr("made Notepad Window screenshot") #EndRegion Notepad Snapshot Creation #Region Test if application appeared Local $y = 0, $x = 0, $result $result = _ImageSearch($testimage, 1, $x, $y, 0, 0);_ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0) If $result = 1 Then cr("! $result=" & $result, 1) MouseMove($x, $y, 0) cr("+" & "recognised notepad! moved mouse to center of notepad!") Else cr("! $result=" & $result, 1) Exit EndIf #EndRegion Test if application appeared #Region Test if application vanished WinSetState($hWin, "", @SW_MINIMIZE) Local $y = 0, $x = 0, $result $result = _ImageSearch($testimage, 1, $x, $y, 0, 0);_ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0) If $result = 1 Then cr("! $result=" & $result, 1) Exit Else cr("! $result=" & $result, 1) cr("+" & "notepad dissapeared!") EndIf #EndRegion Test if application vanished cr() cr("!Test finished") EndIf Exit #EndRegion TESTING/Example #Region ImageSearch Startup/Shutdown Func _ImageSearchStartup() _WinAPI_Wow64EnableWow64FsRedirection(True) $sOSArch = @OSArch ;Check if running on x64 or x32 Windows ;@OSArch Returns one of the following: "X86", "IA64", "X64" - this is the architecture type of the currently running operating system. $sAutoItX64 = @AutoItX64 ;Check if using x64 AutoIt ;@AutoItX64 Returns 1 if the script is running under the native x64 version of AutoIt. If $sOSArch = "X86" Or $sAutoItX64 = 0 Then cr("+>" & "@OSArch=" & $sOSArch & @TAB & "@AutoItX64=" & $sAutoItX64 & @TAB & "therefore using x32 ImageSearch DLL") $h_ImageSearchDLL = DllOpen("ImageSearchDLLx32.dll") If $h_ImageSearchDLL = -1 Then Return "DllOpen failure" ElseIf $sOSArch = "X64" And $sAutoItX64 = 1 Then cr("+>" & "@OSArch=" & $sOSArch & @TAB & "@AutoItX64=" & $sAutoItX64 & @TAB & "therefore using x64 ImageSearch DLL") $h_ImageSearchDLL = DllOpen("ImageSearchDLLx64.dll") If $h_ImageSearchDLL = -1 Then Return "DllOpen failure" Else Return "Inconsistent or incompatible Script/Windows/CPU Architecture" EndIf Return True EndFunc ;==>_ImageSearchStartup Func _ImageSearchShutdown() DllClose($h_ImageSearchDLL) _WinAPI_Wow64EnableWow64FsRedirection(False) cr(">" & "_ImageSearchShutdown() completed") Return True EndFunc ;==>_ImageSearchShutdown #EndRegion ImageSearch Startup/Shutdown #Region My Custom ConsoleWrite/debug Function Func cr($text = "", $addCR = 1, $printTime = False) ;Print to console Static $sToolTip If Not @Compiled Then If $printTime Then ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " ") ConsoleWrite($text) If $addCR >= 1 Then ConsoleWrite(@CR) If $addCR = 2 Then ConsoleWrite(@CR) Else If $printTime Then $sToolTip &= @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " " $sToolTip &= $text If $addCR >= 1 Then $sToolTip &= @CR If $addCR = 2 Then $sToolTip &= @CR ToolTip($sToolTip) EndIf Return $text EndFunc ;==>cr #EndRegion My Custom ConsoleWrite/debug Function  
       
       
       
×