Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. ; ------------------------------------------------------------------------------
  2. ;
  3. ; AutoIt Version: 3.0
  4. ; Language: English
  5. ; Description: Functions that assist with Image Search
  6. ; Require that the ImageSearchDLL.dll be loadable
  7. ;
  8. ; ------------------------------------------------------------------------------
  9.  
  10. ;===============================================================================
  11. ;
  12. ; Description: Find the position of an image on the desktop
  13. ; Syntax: _ImageSearchArea, _ImageSearch
  14. ; Parameter(s):
  15. ; $findImage - the image to locate on the desktop
  16. ; $tolerance - 0 for no tolerance (0-255). Needed when colors of
  17. ; image differ from desktop. e.g GIF
  18. ; $resultPosition - Set where the returned x,y location of the image is.
  19. ; 1 for centre of image, 0 for top left of image
  20. ; $x $y - Return the x and y location of the image
  21. ; $transparency - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
  22. ; the color to be used as transparency; can be omitted if
  23. ; not needed
  24. ;
  25. ; Return Value(s): On Success - Returns 1
  26. ; On Failure - Returns 0
  27. ;
  28. ; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
  29. ; a desktop region to search
  30. ;
  31. ;===============================================================================
  32.  
  33. Func _ImageSearch($findImage,$resultPosition, ByRef $x, ByRef $y,$tolerance,$transparency=0)
  34. return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance,$transparency)
  35. EndFunc
  36.  
  37. Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom, ByRef $x, ByRef $y, $tolerance, $transparency=0)
  38. ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
  39. if not ($transparency = 0) then $findImage = "*" & $transparency & " " & $findImage
  40. if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
  41. $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
  42.  
  43. ; If error exit
  44. if $result[0]="0" then return 0
  45.  
  46. ; Otherwise get the x,y location of the match and the size of the image to
  47. ; compute the centre of search
  48. $array = StringSplit($result[0],"|")
  49.  
  50. $x=Int(Number($array[2]))
  51. $y=Int(Number($array[3]))
  52. if $resultPosition=1 then
  53. $x=$x + Int(Number($array[4])/2)
  54. $y=$y + Int(Number($array[5])/2)
  55. endif
  56. return 1
  57. EndFunc
  58.  
  59.  
  60. ;===============================================================================
  61. ;
  62. ; Description: Wait for a specified number of seconds for an image to appear
  63. ;
  64. ; Syntax: _WaitForImageSearch, _WaitForImagesSearch
  65. ; Parameter(s):
  66. ; $waitSecs - seconds to try and find the image
  67. ; $findImage - the image to locate on the desktop
  68. ; $tolerance - 0 for no tolerance (0-255). Needed when colors of
  69. ; image differ from desktop. e.g GIF
  70. ; $resultPosition - Set where the returned x,y location of the image is.
  71. ; 1 for centre of image, 0 for top left of image
  72. ; $x $y - Return the x and y location of the image
  73. ; $transparency - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
  74. ; the color to be used as transparency can be omitted if
  75. ; not needed
  76. ;
  77. ; Return Value(s): On Success - Returns 1
  78. ; On Failure - Returns 0
  79. ;
  80. ;
  81. ;===============================================================================
  82. Func _WaitForImageSearch($findImage,$waitSecs,$resultPosition, ByRef $x, ByRef $y,$tolerance,$transparency=0)
  83. $waitSecs = $waitSecs * 1000
  84. $startTime=TimerInit()
  85. While TimerDiff($startTime) < $waitSecs
  86. sleep(100)
  87. $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance,$transparency)
  88. if $result > 0 Then
  89. return 1
  90. EndIf
  91. WEnd
  92. return 0
  93. EndFunc
  94.  
  95. ;===============================================================================
  96. ;
  97. ; Description: Wait for a specified number of seconds for any of a set of
  98. ; images to appear
  99. ;
  100. ; Syntax: _WaitForImagesSearch
  101. ; Parameter(s):
  102. ; $waitSecs - seconds to try and find the image
  103. ; $findImage - the ARRAY of images to locate on the desktop
  104. ; - ARRAY[0] is set to the number of images to loop through
  105. ; ARRAY[1] is the first image
  106. ; $tolerance - 0 for no tolerance (0-255). Needed when colors of
  107. ; image differ from desktop. e.g GIF
  108. ; $resultPosition - Set where the returned x,y location of the image is.
  109. ; 1 for centre of image, 0 for top left of image
  110. ; $x $y - Return the x and y location of the image
  111. ; $transparent - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
  112. ; the color to be used as transparent; can be omitted if
  113. ; not needed
  114. ;
  115. ; Return Value(s): On Success - Returns the index of the successful find
  116. ; On Failure - Returns 0
  117. ;
  118. ;
  119. ;===============================================================================
  120. Func _WaitForImagesSearch($findImage,$waitSecs,$resultPosition, ByRef $x, ByRef $y,$tolerance,$transparency=0)
  121. $waitSecs = $waitSecs * 1000
  122. $startTime=TimerInit()
  123. While TimerDiff($startTime) < $waitSecs
  124. for $i = 1 to $findImage[0]
  125. sleep(100)
  126. $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance,$transparency)
  127. if $result > 0 Then
  128. return $i
  129. EndIf
  130. Next
  131. WEnd
  132. return 0
  133. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement