fast getpixelcolor ?

Ask gaming related questions
Trigun
Posts: 23
Joined: 29 Mar 2017, 01:33

fast getpixelcolor ?

07 Jan 2019, 08:57

hi
i made a small script for click on the right zone of a minigame
Image

x = first white pixel from left
x2 = first white pixel from right
x3 = position of the red bar

if the red bar is in the right side it go from right to left otherwise and i switch x2 with x and start the 2nd cicle where i search when the red bar go on the clickable area and send the click
the problem i think is a fps lag or something else so i need to check more than a pixel for the bar but if i add other PixelGetColor it will reduce the accuracy of the check
the minigame last less than a second

any hint how i can increase the accuracy of the 2nd while?

Code: Select all

i:=0
while i<4000 {
  PixelSearch, x, y, 780, 890, 1160, 890, 0xFFFFFF , 5, fast
  if (ErrorLevel = 0) {
    j :=0
    PixelSearch, x2, y, x, 890, 1160, 890, 0x7F7F7F , 5, fast
    PixelSearch, x3, y, 750, 890, 1180, 890, 0xFF0000 , 5, fast RGB
    if (x3 > 1100) {
        x := x2 +30  
    }
    else {
        x:=x-30  
    }

    while j<100 { ;found the white area
        PixelGetColor, color, x,y, RGB
        ifEqual, color, %red% 
        {
            Click 
            sleep, 200
            break             
        }
        j++
    }
  }    
  sleep, 20
  i++
}
User avatar
evilC
Posts: 4690
Joined: 27 Feb 2014, 12:30

Re: fast getpixelcolor ?

09 Jan 2019, 08:19

You are pointlessly searching stuff.

PixelSearch, x, y, 780, 890, 1160, 890, 0xFFFFFF , 5, fast finds the x coordinate of the right-most white pixel
Then PixelSearch, x2, y, x, 890, 1160, 890, 0x7F7F7F , 5, fast presumably is looking for the grey area after the white area, and starts searching at the point that the previous search matched.
Finally, you seem to be looking for the red bar using PixelSearch, x3, y, 750, 890, 1180, 890, 0xFF0000 , 5, fast RGB, however you start searching from x750 - further left than you started searching in the beginning ?!?
Surely you would want PixelSearch, x3, y, x2, 890, 1180, 890, 0xFF0000 , 5, fast RGB

Finally, bear in mind that with PixelSearch, all of your searches may well not be on the same image.
If, for example, the bar moves around quite rapidly, it will not work as expected.
You could try using my CGDipSnapshot library, which while it lacks an equivalent of PixelSearch, does allow you to take a "Snapshot" of a portion of the screen, and perform operations on the snapshot (Which will not change) rather than the screen (Which will change).
Seeing as all you effectively need to do is to search a 1px high strip of pixels, PixelSearch is not really helping you that much.
https://www.autohotkey.com/boards/viewtopic.php?t=5682
Trigun
Posts: 23
Joined: 29 Mar 2017, 01:33

Re: fast getpixelcolor ?

09 Jan 2019, 19:41

i search for the start and end of the white area since the bar can start from right or left
the +30 pixel is for the delay/lag
the bar start from 1 edge till the other side without reverse the direction and all the travel last less than a second
i tried to start a timer after the x3 and got 200-600ms from the click in the few test i did with the timer

btw i'll try that link and see if works better :-)
Trigun
Posts: 23
Joined: 29 Mar 2017, 01:33

Re: fast getpixelcolor ?

11 Jan 2019, 11:51

much better ^^
i tried with

Code: Select all

x:=760
y:=100
j:=0
start := A_TickCount

    while j<65 { 
        snap := new CGdipSnapshot(750 ,890, 430, 1)  
        snap.TakeSnaphot()
        val1 :=snap.PixelScreen[x,890].rgb
        val2 :=snap.PixelScreen[x+5,890].rgb
        val3 :=snap.PixelScreen[x-5,890].rgb
        if (val1 = red or val2 = red or val3 = red)
        {
            Click 
            sleep, 200
                         
        }
        j++
        }
        timeA := A_TickCount-start
     j:=0   
     start := A_TickCount                    
     while j<65 {     
        
        PixelGetColor, color, x,y, RGB
        ifEqual, color, %red% 
        {
            Click 
            sleep, 200           
        }
        j++
        
        
    }
    timeB := A_TickCount-start
    tooltip, dll %timeA% getcolor %timeB%
i changed my function and added a sleep, 20 too ^_^

Code: Select all

  while i<1000 { 
    PixelSearch, x, y, 780, 890, 1160, 890, 0xFFFFFF , 5, fast
    if (ErrorLevel = 0) {
      j :=0   
      PixelSearch, x2, y, x, 890, 1160, 890, 0x7F7F7F , 5, fast
      PixelSearch, x3, y, 750, 890, 1180, 890, 0xFF0000 , 5, fast RGB
      if (x3 > 1100) {
          x := x2 +30  
      }
      else {
          x:=x-30  
      }              
      while j<65 { 
          snap := new CGdipSnapshot(750 ,890, 430, 1)  
          snap.TakeSnaphot()
          val1 :=snap.PixelScreen[x,890].rgb
          val2 :=snap.PixelScreen[x+5,890].rgb
          val3 :=snap.PixelScreen[x-5,890].rgb
          if (val1 = red or val2 = red or val3 = red)
          {
              Click 
              sleep, 800
              break             
          }
          j++   
      }
    }    
    sleep, 20
    i++
  }
thanks :-)

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 22 guests