AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PixelSearch Questions

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
me10c



Joined: 22 Nov 2008
Posts: 27

PostPosted: Mon Dec 22, 2008 5:13 pm    Post subject: PixelSearch Questions Reply with quote

Code:
#g::
loop
{
   PixelSearch, Px, Py, x1, y1, x2, y2,C,C2,C3, 3, Fast            ;Action One (A1)
   Click, %Px%, %Py%
   PixelSearch, Px, Py, Relx, Rely,C, Fast               ;Action Two (A2)
   if Px = C
      {
      Return to A2
      }
   else
      {
      Return to A1
      }
   PixelSearch, Px, Py,  x1, y1, x2, y2, C4, 3, Fast
   if Px = C4
      {
      break
      }
   else
      {
      return to A2
      }
}
return

THIS IS NOT THE REAL CODE (part of it might be lol Very Happy), its just a "thing" I made to remind myself what I want to do.
C,C2...C4 = different colors

The purpose
- The script checks for few colors (lets say 3 types of yellow) (action 1)
- If the script finds any ot the listed colors click on the spot with that color
- The script checks if the last picked color on that spot has changed (lets say the script choosed Yellow N2 and clicks on in, then it checks if the color is still the same) (action 2)
- If the color is the same - return to action 2
- If the color is different - return to action 1
- If a C4 (lets say blue) appears somewhere on the screen the script breaks the loop

The questions:
- How to make the script so it will be able to check for multiple colors at the same time ?
- How to force the script to return to Action 1/2 when it requires
- How to force the script not to click at the lower X and Y points when it ?finds the color (it always clicks at the 1st found pixel ... in other words if you have Yellow at x50, y50 ; x100, y100 ; x200, y 200 etc. it will always click at x50, y50) ?


Last edited by me10c on Tue Dec 23, 2008 6:45 pm; edited 1 time in total
Back to top
View user's profile Send private message
Andi



Joined: 11 Feb 2005
Posts: 165
Location: Germany, Niestetal

PostPosted: Mon Dec 22, 2008 9:57 pm    Post subject: Reply with quote

two things I don't understand.

In my opinion you can only search for one color at a time. Look at the helpfile!!

You can't use this:
Code:
PixelSearch, Px, Py, x1, y1, x2, y2,C,C2,C3, 3, Fast

here you compare a position with a color, thats the same like comparing apples and pears...

Code:
if Px = C
Back to top
View user's profile Send private message
me10c



Joined: 22 Nov 2008
Posts: 27

PostPosted: Mon Dec 22, 2008 10:05 pm    Post subject: Reply with quote

this isnt the code actually .. it was a base I wrote so I wont forget what I want to do ...

Code:
PixelSearch, Px, Py, x1, y1, x2, y2,C,C2,C3, 3, Fast

I want the script to search for more then 1 color in the square .. (from x1 to x2 and from y1 to y2) and if it finds it to click on it ...
the "thing" above is just to have the ... visual idea ... c,c2,c3 of course will be replaced with the proper code ...
still the more importnat is how to make the action thing .. and if possible not to click at the same coordinate agan and again
Back to top
View user's profile Send private message
me10c



Joined: 22 Nov 2008
Posts: 27

PostPosted: Tue Dec 23, 2008 7:25 pm    Post subject: Reply with quote

bump
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 2342

PostPosted: Tue Dec 23, 2008 11:24 pm    Post subject: Reply with quote

For greater flexibility, you can use a functionized version of PixelSearch. For instance:
Code:
c = 0xded9d2
c2 = 0xa16e09
c3 = 0xffe3d0
#g::
   If ( pos := PixelSearch((qc := C) . " 3 fast", x1, y1, x2, y2 ) )
   || ( pos := PixelSearch((qc := C2) . " 3 fast", x1, y1, x2, y2 ) )
   || ( pos := PixelSearch((qc := C3) . " 3 fast", x1, y1, x2, y2 ) )
   {
      Click, % ((pos >> 16) - 32768) . " " . ((pos & 65535) - 32768)
      tooltip, The color %qc% was clicked.
   }
return

; Functionized pixelsearch, version 5.2
; use parameter 1 for the color, variance, fast, and rgb
; options, seperated by a literal space or a literal comma
; example: result := PixelSearch("0x123456, 7, fast, rgb", 15, 20, 25, 30)
; Additionally, the option 'screen' can be used when
; [CoordMode, Pixel, Screen] is in effect to change the default
; search bounds to match the screen, rather than the active window.
; The return value is zero if and only if the pixel was not found
; if there was a problem, the return value is null
; if the pixel was found, the return value is the encoded coordinates
; use FoundX := (result >> 16) - 32768 ; or (result // 0x10000) - 0x8000
; and FoundY := (result & 65535) - 32768 ; or Mod(result, 0x10000) - 0x8000
; The following example will move the mouse cursor to the first found
; white pixel in the current active window:
; If (coords := PixelSearch("0xFFFFFF fast"))
;    MouseMove, % (coords >> 16) - 32768, % (coords & 65535) - 32768, 5
;
PixelSearch(color = 0, left = "", top = "", right = "", bottom = "")
{
   var := 0
   If (left = "" || top = "")
   WinGetPos,,, Width, Height, A
   If InStr(Color, "fast")
      options = "Fast"
   If InStr(Color, "RGB")
      options .= (options ? " " : "") "RGB"
   If InStr(Color, "screen")
      width := A_ScreenWidth, height := A_ScreenHeight
   Loop, Parse, color, `, %A_Tab%
   {
      IfEqual, col,, SetEnv, col, % SubStr(A_LoopField,1,8)
      else If A_LoopField IS Number
         var := Round(A_LoopField)
      break
   }
   IfEqual, right,, SetEnv, right, % left="" ? width + (left:=0) : left
   IfEqual, bottom,, SetEnv, bottom, % top="" ? height + (top:=0) : top
   PixelSearch, ox, oy, left, top, right, bottom, %col%, %var%, %options%
   IfEqual, ErrorLevel, 0, return ((ox+32768) << 16) | (oy + 32768)
   return Errorlevel = 2 ? "" : 0
}

Such a function can be easily incorporated into expressions and if statements because its return value is non-false when it finds the color. This is only one variation of many different functions made for this command. Try searching the forums for some other ones.
_________________
My Home Thread
Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
me10c



Joined: 22 Nov 2008
Posts: 27

PostPosted: Thu Jan 08, 2009 12:26 pm    Post subject: Reply with quote

How was the code to :
search a color in a square (lets say 200-300 x, 200-300 y)
and click on it ...
(seriusly i forgot Shocked )
Back to top
View user's profile Send private message
BoBoł
Guest





PostPosted: Thu Jan 08, 2009 1:13 pm    Post subject: Reply with quote

Quote:
seriusly i forgot
Nevermind. Take your time. Think harder. We believe in you! Cool
Back to top
Guest






PostPosted: Thu Jan 08, 2009 2:01 pm    Post subject: Reply with quote

BoBoł wrote:
Quote:
seriusly i forgot
Nevermind. Take your time. Think harder. We believe in you! Cool

If I knew that I can remember it I wouldnt ask here ...
Back to top
evan
Guest





PostPosted: Thu Jan 08, 2009 2:28 pm    Post subject: Reply with quote

well i believe in u too
if u cant remember, start from scratch again
read help file about pixelsearch and the errorlevel then just combine with click
Back to top
me10c



Joined: 22 Nov 2008
Posts: 27

PostPosted: Thu Jan 08, 2009 5:39 pm    Post subject: Reply with quote

I hate when you tell people that you can find a fkin 4 lines code and you cant remember it , and :
1 - they just say something useless
2 - they say something useless.
Back to top
View user's profile Send private message
me10c



Joined: 22 Nov 2008
Posts: 27

PostPosted: Mon Jan 12, 2009 11:10 am    Post subject: Reply with quote

Still cant find it/remember it ... if someone would be so kind to post the code (which im sure its no more then 5 lines) I would be pretty grateful ...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group