epicfail

image search helpwith gui

16 posts in this topic

#1 ·  Posted (edited)

hi how would i get this to work with a gui with buttons 4 each image to find i tryed to add it to my script but i cant seem to get it working.

#include <ImageSearch.au3>

;
; Demo on the functions of ImageSearch
; Assumes that you have a Recycle Bin icon at the top left of your screen
; Assumes that you have IE6 or 7 icon visible
; Please make the icon visible or we won't be able to find it
;

MsgBox(0,"MSG","You need to have the should have recycle bin, and preferably, an IE icon, a PDF icon and folder icon for the demo to go nicely. All of them should be visible on the desktop")

$x1=0
$y1=0



; I guess most people should at least have an PDF icon on the desktop
$result = _ImageSearch("exit2.bmp",1,$x1,$y1,0)
if $result=1 Then
    MouseMove($x1,$y1,1)
    MsgBox(0,"Found","Found a PDF icon here")
EndIf

; I guess most people should at least have an Folder icon on the desktop
$result = _ImageSearch("folder.bmp",0,$x1,$y1,0)
if $result=1 Then
    MouseMove($x1,$y1,3)
    MsgBox(0,"Found","Found a Folder icon here")
EndIf

; wait for a non empty recycle bin to appear
MsgBox(0,"MSG","Empty your recycle bin and then click OK. Then throw something in the bin within 15s")
$result = _WaitForImageSearch("recycle.bmp",15,1,$x1,$y1,0)
if $result=1 Then
    MouseMove($x1,$y1,3)
    MsgBox(0,"Found","Hey... your recycle bin now has stuff")
EndIf

; wait 15s for either the full or empty recycle bin
MsgBox(0,"MSG","Using WaitForImages to see whether you have a full or empty bin")
Dim $anArray[10]
$anArray[0]=2  ; two images to wait to appear
$anArray[1]="recycle.bmp"  ; image 1 to wait for
$anArray[2]="recycle2.bmp"  ; image 2 to wait for
$result = _WaitForImagesSearch($anArray,15,1,$x1,$y1,0)
if $result=1 Then
    MouseMove($x1,$y1,3)
    MsgBox(0,"Found","Hey... your recycle bin has stuff")
EndIf
if $result=2 Then
    MouseMove($x1,$y1,3)
    MsgBox(0,"Found","Hey... your recycle bin is empty")
EndIf
if $result=0 Then
    MouseMove($x1,$y1,3)
    MsgBox(0,"Found","Hey... cannot find your recycle bin")
EndIf

my script i want to add the imagesearch where im using the mouse clicks but it wasnt working 4 me.

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
#include <Timers.au3>
#include <IE.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ImageSearch.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 329, 123, 192, 124)
$Input1 = GUICtrlCreateInput("Email", 72, 16, 185, 21)
$Input2 = GUICtrlCreateInput("Password", 72, 40, 185, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
$Button1 = GUICtrlCreateButton("Start Bot", 56, 88, 105, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Exit", 168, 88, 105, 25, $WS_GROUP)
$Checkbox1 = GUICtrlCreateCheckbox("Save Email & Password", 72, 64, 129, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


_Sleep(10000) ; sleep for 10 seconds but GUI messages can still come through : ) : )  : )

Func _Sleep($wait, $delay = 10)
   $init = TimerInit()
   While TimerDiff($init) < $wait
      Sleep($delay)
      ApplicationDoEvents()
   Wend
EndFunc

Func ApplicationDoEvents()
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case -3 ; $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            start()
        Case $Button2
            _Exit()
    EndSwitch
EndFunc

Func start()
    while 1

    $oIE = _IECreate ("www.mysite.com")
    $HWND = _IEPropertyGet($oIE, "hwnd")
    WinSetState($HWND, "", @SW_MAXIMIZE)
    _IELoadWait ($oIE)
    $oform = _IEFormGetObjByName($oIE, "menubar_login")
    $oQuery = _IEFormElementGetObjByName($oform, "email")
    $o_Query = _IEFormElementGetObjByName($oform, "pass")

    $username = GUICtrlRead($Input1)
    $password = GUICtrlRead($Input2)

    _IEFormElementSetValue($oQuery, $username)
    _IEFormElementSetValue($o_Query, $password)

    Send("{TAB}{ENTER}")

    _IELoadWait ($oIE)
    MouseMove(765,391)
    MouseDown("left")
    MouseUp("left")
    _Sleep(8000)
    MouseMove(775,367)
    MouseDown("left")
    MouseUp("left")
    _Sleep(8000)
    MouseMove(774,380)
    MouseDown("left")
    MouseUp("left")
    _Sleep(8000)
    MouseMove(344,256)
    MouseDown("left")
    MouseUp("left")
    _Sleep(8000)
    MouseMove(394,363)
    MouseDown("left")
    MouseUp("left")
    _IEQuit ($oIE)
    _Sleep(800000)
    WEnd

EndFunc


Func _EXIT()
    Exit
EndFunc
Edited by epicfail

Share this post


Link to post
Share on other sites



epicfail, "it wasn't working for me" is not an accurate enough description of your problem. You seem to give this problem description every time.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

okhere is what i tryed and the errors i get. when it gets upto the imagesearch part my program just closes and i get errors

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
#include <Timers.au3>
#include <IE.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ImageSearch.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 329, 123, 192, 124)
$Input1 = GUICtrlCreateInput("Email", 72, 16, 185, 21)
$Input2 = GUICtrlCreateInput("Password", 72, 40, 185, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
$Button1 = GUICtrlCreateButton("Start Bot", 56, 88, 105, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Exit", 168, 88, 105, 25, $WS_GROUP)
$Checkbox1 = GUICtrlCreateCheckbox("Save Email & Password", 72, 64, 129, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$x1=0
$y1=0

_Sleep(100000) ; sleep for 10 seconds but GUI messages can still come through : ) : )  : )

Func _Sleep($wait, $delay = 10)
   $init = TimerInit()
   While TimerDiff($init) < $wait
      Sleep($delay)
      ApplicationDoEvents()
   Wend
EndFunc

Func ApplicationDoEvents()
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case -3 ; $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            start()
        Case $Button2
            _Exit()
    EndSwitch
EndFunc

Func start()
    while 1

    $oIE = _IECreate ("www.mysite.com")
    $HWND = _IEPropertyGet($oIE, "hwnd")
    WinSetState($HWND, "", @SW_MAXIMIZE)
    _IELoadWait ($oIE)
    $oform = _IEFormGetObjByName($oIE, "menubar_login")
    $oQuery = _IEFormElementGetObjByName($oform, "email")
    $o_Query = _IEFormElementGetObjByName($oform, "pass")

    $username = GUICtrlRead($Input1)
    $password = GUICtrlRead($Input2)

    _IEFormElementSetValue($oQuery, $username)
    _IEFormElementSetValue($o_Query, $password)

    Send("{TAB}{ENTER}")

    _IELoadWait ($oIE)

$result = _ImageSearch("folder.bmp",0,$x1,$y1,0)
if $result=1 Then
    MouseMove($x1,$y1,3)
    MsgBox(0,"Found","Found a Folder icon here")
EndIf

    _Sleep(8000)
    MouseMove(775,367)
    MouseDown("left")
    MouseUp("left")
    _Sleep(8000)
    MouseMove(774,380)
    MouseDown("left")
    MouseUp("left")
    _Sleep(8000)
    MouseMove(344,256)
    MouseDown("left")
    MouseUp("left")
    _Sleep(8000)
    MouseMove(394,363)
    MouseDown("left")
    MouseUp("left")
    _IEQuit ($oIE)
    _Sleep(800000)
    WEnd

EndFunc


Func _EXIT()
    Exit
EndFunc

D:\Program Files\AutoIt3\Include\ImageSearch.au3 (40) : ==> Subscript used with non-Array variable.:
if $result[0]="0" then return 0
if $result^ ERROR

The include

#include-once
; ------------------------------------------------------------------------------
;
; 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)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance)
EndFunc

Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)
    ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
    if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)

    ; 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 $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)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
        sleep(100)
        $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance)
        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)
    $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)
            if $result > 0 Then
                return $i
            EndIf
        Next    
    WEnd
    return 0
EndFunc
Edited by epicfail

Share this post


Link to post
Share on other sites

ok i just put the dll in the same folder but my program just closes i get error

!>22:09:45 AutoIT3.exe ended.rc:-1073741819

Share this post


Link to post
Share on other sites

Does the ImageSearchDemo.au3 that comes with the ImageSearch library work for you? (Or at least, doesn't crash? )

If you have obtained the ImageSearch DLL and libraries a while ago, try redownloading them.

Share this post


Link to post
Share on other sites

the demo works and i downloaded today. i just tryed it on my other computer with windows7 it didnt crash but it scipped the image search and went to the next mouse move

Share this post


Link to post
Share on other sites

ok the demo keeps crashing on this computer. i have re downloaded it.

Share this post


Link to post
Share on other sites

is he simply trying to find image files inside a folder?

then why not simply use filefindfirstfile() & search for files with image extensions?


My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

is he simply trying to find image files inside a folder?

then why not simply use filefindfirstfile() & search for files with image extensions?

Judging from all the _IE stuff above he's doing something in a website, thank you very much.

Share this post


Link to post
Share on other sites

ok i got it working with my script there was something wrong with my include. thanks 4 the help man. there is 1 other thing dosnt the imagesearch work 4 vista/windows7?

Share this post


Link to post
Share on other sites

This guy says it works under Vista: http://www.autoitscript.com/forum/index.php?showtopic=65748&view=findpost&p=642268

And I just tried on Windows 7, that worked fine.

Share this post


Link to post
Share on other sites

damn its not working on my windows7

Share this post


Link to post
Share on other sites

i cant seem to get it to click any icons on the desktop.I used print screen to get the picto click on.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

you must put file .dll in folder run

Edited by h.thanh1410

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

@h.thanh1410 be sure that not come back  old topics. topic is about 5 years ago. last visited of epicfail was in 2010.

 

Saludos

Edited by Danyfirex

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