Sign in to follow this  
Followers 0
Schoening

ImageSearch Until. (Operator Question)

5 posts in this topic

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



#2 ·  Posted (edited)

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

#3 ·  Posted (edited)

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

ill try it out after Runnin ^^ Thx

Share this post


Link to post
Share on other sites

(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  
Followers 0

  • Similar Content

    • 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
    • magmet00
      By magmet00
      Do you have a working imagesearch.au3 with working dll?
      and how can i gethandle and send keyboard/mouse commands to hidden d3d window?
       
      i have tried imagesearch2015 but im getting dll error every time and tried older imagesearchs too in forum what i found.
      i have tried many things to send commands to hidden/background d3dwindow still nothing works.
      Can you help me please?
       
    • knuxfighter
      By knuxfighter
      Hello. I've been working with Imagesearch library lately and it did a good work, although I moved to a new PC and didn't copy the old files with me so I downloaded the Imagesearch from the following post
       hoping that it will work. It doesn't though. First time I when I use (run as subscript to my code) the Imagesearch.au3, Scite finds errors (missing spaces). Ctrl+T (scite tidy) fixes these missing spaces but the script returns the following error on every run after:
      _ImageSearch('search.bmp', 0, $x, $y, 0) outputs
       
      "C:\Users\Knuckles\Desktop\AutoIt\include\ImageSearch.au3" (44) : ==> Subscript used on non-accessible variable.: If $result[0] = "0" Then Return 0 If $result^ ERROR no matter if I put the searched bmp in the script folder or folder img in the script directory. Also, it doesn't matter if the searched image on screen or not, it returns the same.

      Can you provide me any help please? I remember having these problems 2 years ago when I first met the imagesearch library also (I fixed it somehow though in that time). Seems nothing changed.

      Using this version posted in the following post gives the same error:
      Also I run windows 10 64bit and I have no shell options for script editing, running as x86 or whatever as I used to have on windows xp/7. I went through some steps like deleting a key in registry and I even reinstalled autoit and scite but that only resulted to au3 as unrecognized file format and not in getting back the menus and the icon on au3 files. Any thoughts on this?

      Edit: Installing 64-bit AutoIt and using 64bit ImageSearch is no change.
      code.au3

      FOUND WORKING: http://www.codebot.de/index.php/Thread/12713-Imagesearch-au3-funktioniert-nicht/
       but why is this one working and the original aren't? :(
    • masterland
      By masterland
      Hello.
      I had made a bot that clicks and doing stuff. It is working fine, but when i move it to another PC ImageSearch stop working. I captured same image of a button again and i observed that they are a little bit different. How to deal with this? I wonder if i will make black and white detection might work, or not ... i don't know. The point is i am not willing to re-do photos on each and every PC i move the scripts.
       
      ClickOnImageWithToleranceFast("images/fb_about.bmp",16) Func ClickOnImageWithToleranceFast($image_path,$tolerance) If SearchForImageOnScreenWithTolerance($image_path,$tolerance) Then If $x <> 0 And $y <> 0 Then MouseMove($x+5, $y+5,0) Sleep(500) MouseClick("left") Sleep(500) EndIf EndIf EndFunc  
      Link : https://postimg.org/gallery/z6n168ps/585debf1/#
      Also i have attached them.
      Thank you
      fb_about.bmp
      fb_about2.bmp
    • Miliardsto
      By Miliardsto
      Hello i got problem with ImageSearchDll.dll
      It works for me perfect always I made program which one use a lot of ImageSearch funcs on 64bit.
      I got 64bit and i copied to c:/Windows - ImageSearchDll.dll 64bit version
      But I encountered some friends got 32bit OS and then if I compile program for 32bit then they put ImageSearchDll.dll 32bit ver on windows dir and program crash when function is call.
      it happens always :/
       
      How to run this func on 32bit?