Jump to content
Zag8888

Check every 10sec _ImageSearch()

Recommended Posts

Hi, I want to check every 10 seconds (using _ImageSearch) If the image is found.  I hope someone can help me, thanks!

#include <_ImageSearch.au3>
#include <_ImageSearch_Debug.au3>
$Image = _ImageSearch("Seach_2.bmp",10,True)


While $Image[0] <> 1 ;The script just sleep, instead of checking every 10 seconds.
   Sleep(10000)
WEnd

 

 

 

 

Share this post


Link to post
Share on other sites

Your imagesearch needs to be inside the loop, it only checks it once before going into the loop as written.


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
12 hours ago, BrewManNH said:

Your imagesearch needs to be inside the loop, it only checks it once before going into the loop as written.

Now it works! But the while loop will not end also if the image is found...

Share this post


Link to post
Share on other sites

You know that every functions returns some indication telling you that the function endet successfully or that an error occurred? Depending on this indication you have to check for the image again or leave the loop.
The rest is pure AutoIt ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
1 hour ago, Bert said:

Why do you need to search for an image every 10 seconds? why not just hook into the control and get it's state?

Can you please explain how can I do this? Thanks

Share this post


Link to post
Share on other sites
3 hours ago, Zag8888 said:

Can you please explain how can I do this? Thanks

Only if you are willing to share what you are doing exactly or else it is guess work.

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
12 minutes ago, Jos said:

Only if you are willing to share what you are doing exactly or else it is guess work.

Jos

That's the full code, I just want to try this function, because for me it never worked.

Share this post


Link to post
Share on other sites

Sure...but WHAT do you want to use this for so WE can try to help you... Else please don't waste our time and forum space. Clear enough for you this time?

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
21 minutes ago, Jos said:

Sure...but WHAT do you want to use this for so WE can try to help you... Else please don't waste our time and forum space. Clear enough for you this time?

Jos

I made a photo, I just want the script click on this photo when its found, that's all. I just want to learn Autoit, I'm liking it a lot!

Share this post


Link to post
Share on other sites

 You are lucky that I have seen your topic !

=======

First of all, you shouldn't use the ordinary image search function...as it is not good because it requires that the image appears on the screen, so you can't do any other thing while the script is running

,so you need  the ~:{:}{ImageSearchEX}{:}:~ function

by it,you can search for the image in a specific window...and the function don't require that the image appears on the screen >> only it should appear on the window

,so this function run in the background

=======

Image Search EX Topic  : https://www.autoitscript.com/forum/topic/196542-image-search-inactive-window-but-not-minimized/

=======

note that :

1 : This function doesn't run on X64 bit ,so you have to make the script run on 32 bit by using :

#AutoIt3Wrapper_UseX64=NO

2 : This function requires the window to be shown ,not minimized or hidden.

,so if you want to hide the window  : just move it to (-X , -Y) Position that is out of the screen

======

Eventually : Here is the code you need :

#NoTrayIcon
#AutoIt3Wrapper_UseX64=NO
#include <imageSearchEX.au3>

Global $imageSearchEX = imageSearchEX
Global $_Check_Image  = _Check_Image

$Your_Window = "";your window
$Your_Control = "";your Control
$Your_Image = "";your Image

While 1
$Coords = $_Check_Image($Your_Window,$Your_Control,$Your_Image)
If $Coords <> 0 Then
    ;Do Something
    ExitLoop
EndIf
Sleep(10000) ;Sleep 10 Seconds
WEnd


Func _Check_Image($Window, $Control, $Image)
$Hwnd = WinGetHandle($Window)
$Control_Pos = ControlGetPos($Hwnd,$Control)
$Coords = $imageSearchEX($Hwnd,$Image)
Return $Coords
EndFunc

 

 

 

Share this post


Link to post
Share on other sites

Sorry,the code is not complete ..i didn't revise it 🤒

Also, there is no (Edit) Button 🙄

Here it is :

#NoTrayIcon
#AutoIt3Wrapper_UseX64=NO
#include <imageSearchEX.au3>

Global $imageSearchEX = imageSearchEX
Global $_Check_Image  = _Check_Image

$Your_Window = "";your window
$Your_Control = "";your Control
$Your_Image = "";your Image

While 1
$Coords = $_Check_Image($Your_Window,$Your_Control,$Your_Image)
If $Coords <> 0 Then
    ;Do Something
    ExitLoop
EndIf
Sleep(10000) ;Sleep 10 Seconds
WEnd


Func _Check_Image($Window, $Control, $Image)
$Hwnd = WinGetHandle($Window)
$Control_Pos = ControlGetPos($Hwnd,$Control)
$Coords = $imageSearchEX($Hwnd,$Image)
$Result = $Coords
If $Coords <> 0 Then
    Local $Image_Pos[] = [ $Coords[0] - $Control_Pos[0], $Coords[1] - $Control_Pos[1] ]
    $Result = $Image_Pos
EndIf
Return $Result
EndFunc

 

Share this post


Link to post
Share on other sites

Hey @El-Masry, or should I say @ibrahem...  and what an entrance 😟

10 hours ago, El-Masry said:

You are lucky that I have seen your topic !

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Ah ... the victim role.  I am not shedding any tears as you know that you were not banned because nobody helped you.
You will be on a very short leece so 1 single "mistake" will get you banned. 

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Posted (edited)
On 4/18/2019 at 2:35 PM, Jos said:

You will be on a very short leece so 1 single "mistake" will get you banned. 

Thanks for this 2nd chance 🙂. Also, I have studied the forum rules well. 😀

Edited by El-Masry

Share this post


Link to post
Share on other sites
On 4/18/2019 at 11:44 PM, El-Masry said:

Thanks for this 2nd chance 🙂. Also, I have studied the forum rules well. 😀

Thanks a lot for your help! I'm sorry if I didn't replied, but I was sick 🤒

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

×
×
  • Create New...