Jump to content
Sign in to follow this  
Schoening

ImageSearch Until. (Operator Question)

Recommended Posts

Schoening

Hey,

so after searching the Forums, Google, YouTube and Other Forums, I found ImageSearch!

AnyBody Not Shure what ImageSearch is, it is a pixelsearch that looks for a image file in the ImageSearch.au3 directory and then Looks for it on the Screen :)

Great Stuff !

Here is a Little Example where i Search for a .png

#include <ImageSearch.au3>
$x = 0
$y = 0
$res = _imagesearcharea("GreenYellow.png",1,340,150,940,512,$x,$y,100)
If $res = 1 Then
MouseMove($x,$y,100)
Else
MsgBox(0,"404","Not Found")
EndIf

Just a quick explain on what happens in the function _imagesearcharea:

_imagesearcharea("GreenYellow.png",1,340,150,940,512,$x,$y,100)

_imagesearcharea("image_name" , a*,b*,b*,b*,b*,c*,c*,d*)

a* = Chooses the Return Value for C*. 0 = top x,y Pixel 1 = Center of the Found image.

b* = Coordinates for the Search Window(Top,Left,Right,Bottom)

c* = The Return Variables (See a*)

d* = Variaton between Image and Search.

I'm not sure if the explanation was needed, i just like pretty Topics :D

My actual problem :

I want to make a do_until loop that keeps doing _Imagesearcharea until i drag the desktop icon in the circa Area.

I could do this by just specifying the Search window. But that would be way to Easy :)

Instead i want the Loop to Run until the icon is dragged "near" a predefined spot on one axis using one of the Variables from _Imagesearcharea.

So lets say i want to ImageSearch until i drag it near the middle of the Screen Seen from the X axis.

Until $x = 640

But that is not "Near" ! That is exact ! I want it to Do_Until it is "close" to 640, so it should also stop searching when it is +20 or -20 from 640.

I think i will do this with some advanced Operators ? Math has never been my Strength...

Please Help ;)

Share this post


Link to post
Share on other sites
JLogan3o13

Hi, Schoening. How about using the Random operator? It allows you to generate a min and a max, so:

Until $x = Rand(625, 640, 1)

Edit: Scratch that, I reread your post after hitting enter. You want it to watch for any number within a certain range of 640...

Edited by JLogan3o13

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

Share this post


Link to post
Share on other sites
BrewManNH
Until ($x > 620) And ($x <660) Something like that might work, untested. Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Schoening

(Had to Charge my Mp4 ^^ had time) Works ! Thx:D

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
Sign in to follow this  

  • Similar Content

    • 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  
       
       
       
    • KING_NK
      By KING_NK
      Added Image...I am trying to work out Imagesearch but Its not working perfectly.After pressing Hotkey,Mouse not moving to targeted picture.I tried so hard but still not working.So i post here,need help

    • DeathChicken
      By DeathChicken
      If possible please add or edit the comments to explain how this works.
       
      ;includes functions from other things
      #include <GDIPlus.au3>
      #include <ScreenCapture.au3>
      ;hotkeys
      HotKeySet("{ESC}", _exit)
      HotKeySet("{F1}", _scan)
      ;global variables
      Global $win_title                    ;name of the window
      Global $area_x                        ;
      Global $area_y                        ;
      Global $area_w                       ;
      Global $area_h                        ;
      Global $cursor                         ;
      Global $rect_file                      ;
      Global $hbmpscreen              ;
      Global $i=  1043                      ;moves the rect
      Global $ii=    378                      ;moves the rect
      Global $x=1044                        ;inner rect offset
      Global $y=501                          ;inner rect offset
      Global $hbmprect                    ;image inside rect
      Global $hscreen                        ;image whole screen
                                         
      _GDIPlus_Startup()                    ;?
      ;display hotkeys on screen
      ToolTip("Press F1 to scan | Press ESC to Exit",0,0)
                                          ;infinite loop to keep prog running
      While 1
          Sleep(100)
      WEnd
      Func _scan()
      ;~ reads your screen area:
      _read()
      ;~ converts screen captured into bmp
      _convert()
      ;~ .  Loads converted bmp to be read
      _loadBMP()
      ;~ compares the bmp of your scanned screen to the actual screen that is being displayed
      _compare()
      EndFunc
                                          ;reads screen
      Func _read()
          $hscreen = _ScreenCapture_CaptureWnd("", WinGetHandle($win_title), $area_x, $area_y, $area_x + $area_w, $area_y + $area_h, $cursor)
      EndFunc
                                          ;converts screen into bmp
      Func _convert()
          _GDIPlus_BitmapCreateFromHBITMAP($hscreen)
      EndFunc
                                          ;loads converted screen
      Func _loadBMP()
      _GDIPlus_BitmapCreateFromFile($rect_file)
      EndFunc
                                          ;compares savedBMP to current screen
      Func _compare()
      ;If(                              below code                                     ) = (                   below code           ) Then
      If _GDIPlus_BitmapGetPixel($hbmpscreen, ($i + $x) - $area_x, ($ii + $y) - $area_y) = _GDIPlus_BitmapGetPixel($hbmprect, $x, $y) Then
      ;display message box titled found with a message of found
      MsgBox("","","found")
      ;if above is not correct then
      EndIf
      EndFunc
                                          ;exit func
      Func _exit()
          Exit
      EndFunc
×