Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PixelSearch in certain area of monitor

So I'm trying to find a certain pattern in the middle of the screen in a given area. I'm using the AutoItX library and the PixelSearch method.

  • Rectangle X: 1980
  • Rectangle Y: 630
  • Rectangle Size X: 1240
  • Rectangle Size Y: 180

It's not returning that the pattern has been found, but if I adjust the cords of the rectangle to 0, 0 it shows that the pattern has been found.

The following script used:

  public void MonsterScan()
  {
    if(SixStarMax() == true)
    {
        Console.WriteLine("Pattern found");
    }
  }

  public bool SixStarMax()
  {
    Rectangle rect = new Rectangle(1980, 630, 1240, 180);
    autoSumPoint = AutoItX.PixelSearch(rect, 0xF8F0E0); // 0xF8F0E0
    autoSumPoint2 = AutoItX.PixelSearch(rect, 0xB7AD9F); // 0xB7AD9F
    autoSumPoint3 = AutoItX.PixelSearch(rect, 0xCDC6B8); // 0xCDC6B8
    autoSumPoint4 = AutoItX.PixelSearch(rect, 0x949084); // 0x949084

    if (rect.Contains(autoSumPoint2) == true && rect.Contains(autoSumPoint2) == true && rect.Contains(autoSumPoint3) == true && rect.Contains(autoSumPoint4) == true)
    {
      AutoItX.MouseMove(autoSumPoint.X, autoSumPoint.Y);
      return true;
    }
    else
    {
      return false;
    }
  }

Edit:

Tried to adjust the cordinates to my first screen and I get an error thrown.

System.AccessViolationException: 'An attempt was made to read or write to protected memory. This often indicates that other memory is damaged. '
like image 766
Tweath Avatar asked Oct 03 '17 20:10

Tweath


1 Answers

AutoItX' PixelSearch() has a bug. Possible solutions :

  • See if it's fixed in latest beta.
  • Change coordinates (an old version had X/Y switched).
  • Use PixelGetColor().
  • Find a 3rd party image search dll.
like image 104
user4157124 Avatar answered Oct 24 '22 22:10

user4157124