Jump to content

Pixelsearch


 Share

Recommended Posts

Hi, maybe there is a topic like this. If it is, i didnt find a answer.

So, my question is:

I want to create a pixelsearcher to make a mouseclick IF the pixel comes on. So far so good. What we all know is, that the Internet is not very fast some time. Some times the Servers are to busy or whatever.

So, my problem is, that the button i want to click on, sometimes need a few ms to become able to click.

The whole thing is a while.

 $buy= PixelSearch(355, 728, 861, 856, 0x1D1D1D)
         If Not @error Then
            MouseClick("", $buy[0], $buy[1])

      EndIf

like i said before, the buy button sometimes take a lil bit of time to show up. So heres the question, Is it possible to make a script like:

1. look for the Pixel,

2. if you cant find the pixel, try again 5 times (or for the next 20 ms) to find that pixel

3. If u still do not find the pixel, move on.

thx for support. :-)

Link to comment
Share on other sites

For $i = 1 To 5 ;try 5 times
    $buy = PixelSearch(355, 728, 861, 856, 0x1D1D1D)
    If Not @error Then
        MouseClick("", $buy[0], $buy[1])
        ExitLoop ; Good, you can stop looking
    EndIf
    Sleep(1000) ; bad, wait 1 second and try again
Next

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Using a timer is just as good a way as any, I just saw that as the quickest example in the bounds set out.

Also, don't let a quicker reply put you off posting yours, it's always better for the OP if they have multiple options.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hey, thx for trying to help. that looks very good BUT it doesnt work :/ First, i think u missed the "step -1". So i tried with both variations. To make it a lil bit more easier to understand. I will click on the button "search". After i click the button, it takes a few milliseconds to load the new page with the objects i want to buy one. So:

Step 1: Click on search button

Step 2: search for the pixel. Maybe there is one, maybe not.

Step 3 - 7 are: click on buy, then go back and search again and so on. But thats not the problem beforei dont get Step 2 done. :-D

 

Step1: MouseClick("left", 665, 941, 1, 14) ; search button   ;

  • Yes, i know. these are static coordinates. Its because, in the first try, i worked (still work because pixelsearch doesnt work) with static coords.

Step 2:

For $i = 5 To 1 Step -1 ;try 5 times
             $buy = PixelSearch(355, 728, 861, 856, 0x9F8249)
             If Not @error Then
                 MouseClick("", $buy[0], $buy[1])
                 ExitLoop ; Good, you can stop looking
             EndIf
             Sleep(10) ; bad, wait 1 second and try again
         Next

 

But it just doesnt work. Direct after Step 1 the mouse goes to the middle of the screen. It doesnt try the 5 times or if it does, then without the sleep timer of 10. Because then there should be 50 ms for try.

I red a lot today. I tried Imagesearch and tried to find solutions for the problem. But it just doesnt work. Imagesearch could be much easier, but it doesnt work. Dont know why.

Thx for helping guys. I just start working with autoit 2 days ago. :-)

Link to comment
Share on other sites

Feel free to take a look at my ImageSearch Example. It will help you learn how to use the function.

https://onedrive.live.com/redir?resid=AC6D5603E28A7989!63671&authkey=!ALkxApzjeoHg6m8&ithint=folder%2c

 

Also, without more info, we cannot help you. What is the workflow? Please be as detailed as you can so we can better understand the situation.

A screenshot would also be nice if you can provide one. 

 

 

Link to comment
Share on other sites

Hi, again its me. :-)

First of all, i wanna thank you both for trying to help me out. :-)

@ Beta: thx for the example but it doesnt work if i start it. I started ur example while i was on the autoitscript site. Nothing happened.

2 questions:

1. I have to put the file "imagesearch.au3" in the folder "C:\Program Files (x86)\AutoIt3\Include" right?

2. After that, i need to put the file  "ImageSearchDLL.dll" in the folder "C:\Windows\System32" OR in the Script folder. Right?

Could it be, that the "_imagesearch" function need to be activate after i did step 1 + 2 or something like that? I just ask because if I write "_Image" in AutoIT, it doesnt make "_imagesearch" automaticly. I mean, for example, if i put in the letter "sl", AutoIT gives me automaticly the option "sleep". Just maybe the "_Imagesearch" just doesnt work because of whatever??

Why i need this "#include "GDIPlus.au3". I didnt see this in any example before.

To make it a little bit easier for me to start, i first need to try to get "_imagesearch" working.

Link to comment
Share on other sites

Hi, again its me. :-)

First of all, i wanna thank you both for trying to help me out. :-)

@ Beta: thx for the example but it doesnt work if i start it. I started ur example while i was on the autoitscript site. Nothing happened.

2 questions:

1. I have to put the file "imagesearch.au3" in the folder "C:\Program Files (x86)\AutoIt3\Include" right?

2. After that, i need to put the file  "ImageSearchDLL.dll" in the folder "C:\Windows\System32" OR in the Script folder. Right?

Could it be, that the "_imagesearch" function need to be activate after i did step 1 + 2 or something like that? I just ask because if I write "_Image" in AutoIT, it doesnt make "_imagesearch" automaticly. I mean, for example, if i put in the letter "sl", AutoIT gives me automaticly the option "sleep". Just maybe the "_Imagesearch" just doesnt work because of whatever??

Why i need this "#include "GDIPlus.au3". I didnt see this in any example before.

To make it a little bit easier for me to start, i first need to try to get "_imagesearch" working.

I forgot to add a loop, which caused it to exit immediately if it didn't find anything. I added a Do until found loop so testing becomes easier.

To answer your 2 questions. The dll needs to be in the same directory as the ImageSearch include. You can place these 2 files anywhere, including the AutoIt Include folder, as long as you remember to tell autoit where you stored them. For the default include folder or @scriptdir, just use #Include "ImageSearch.au3". If you are using any other folder, you will use #include "C:\New Folder\ImageSearch.au3". (We must specify the folder in this case.)

Afaik user created functions won't autofill, even if you include them, until you use the function once. Then it will begin to autofill the function name only. I have yet to get context help or context format to work properly. (The little context menu when you add functions, they tell you what the function does and it's expected format.)

Why do I need #include "GDIPlus.au3"? I'm not sure to be honest, but without it, I can't get it to work either. Using _GDIPlus_ImageLoadFromFile($sImgPath) allows us to create an object in memory to search from using the file provided. _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) Allows us to create a handle from the previously created object. The next step is to _ImageSearch using the object.

Also, I use Lightshot to create my png to search for. You can get it at http://app.prntscr.com/en/download.html

I updated the example script to add the Do Until Loop for you. You can redownload it using the same link as before, https://onedrive.live.com/redir?resid=AC6D5603E28A7989!63671&authkey=!ALkxApzjeoHg6m8&ithint=folder%2C 

 

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...