Sign in to follow this  
Followers 0
TyCobb

AutoItX PixelSearch in C#

2 posts in this topic

Hi all! I just started to get into programming a few months ago and took up C# because that is what the programmers at my job work use (ASP.NET and later porting applications to C#). Today I was bored and wanted to make a little bot and look for certain colors. All I saw was that people couldn't get it to work. I saw Ramadash make his own PixelSearch function which is quite nice, however, is quite slow if you have a large search space. You can see by having the mouse cursor move to the x, y coordinates for every pixel.

Now I do apologize if this has already been fixed or brought up because the threads I saw were old, but I didnt really see a solution when I searched :lmao: . I saw people saying that all they get is a 1, some weird string, or nothing.

Here is what I did in C# and I am sure anyone familiar with other languages can easily interpret it into the code they need.

Code in wrapper class. "AutoIT" is the instance name of AutoItX3Class

public static object PixelSearch(int[] TopLeft, int[] BottomRight, int Color, int Shade, int Step)
{
    return AutoIT.PixelSearch(TopLeft[0], TopLeft[1], BottomRight[0], BottomRight[1], Color, Shade, Step);
}

Code to return the coordinates and handle the error.

//AuX_Wrapper is the instance name for my Wrapper
object coord = AuX_Wrapper.PixelSearch(TopLeft, BottomRight, Color, Shade, Step);

//Here we check to see if it found the pixel or not. It always returns a 1 in C# if it did not.
if(coord.ToString() != "1")
{
    //We have to turn "object coord" into a useable array since it contains the coordinates we need.
    object[] pixelCoord = (object[]) coord;
    
    //Now we cast the object array to integers so that we can use the data inside.
    AuX_Wrapper.MouseMove((int)pixelCoord[0], (int)pixelCoord[1], 500);                 
}

I hope this helps. It took me a few minutes to figure out what I needed to do in order to turn the object into a useable variable. ;)

Share this post


Link to post
Share on other sites



WoW thanks

that helped me alot.

I got it workging now ;)=

*in love*

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