AutoHotkey Community

It is currently May 26th, 2012, 12:49 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: PixelSearch Questions
PostPosted: December 22nd, 2008, 6:13 pm 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
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 :D), 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 December 23rd, 2008, 7:45 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 22nd, 2008, 10:57 pm 
Offline

Joined: February 11th, 2005, 6:31 am
Posts: 174
Location: Germany
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 22nd, 2008, 11:05 pm 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 23rd, 2008, 8:25 pm 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
bump


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 24th, 2008, 12:24 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3329
Location: Simi Valley, CA
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.

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2009, 1:26 pm 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
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 :shock: )


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2009, 2:13 pm 
Quote:
seriusly i forgot
Nevermind. Take your time. Think harder. We believe in you! 8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2009, 3:01 pm 
BoBo³ wrote:
Quote:
seriusly i forgot
Nevermind. Take your time. Think harder. We believe in you! 8)

If I knew that I can remember it I wouldnt ask here ...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2009, 3:28 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2009, 6:39 pm 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 12th, 2009, 12:10 pm 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
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 ...


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Cerberus, patgenn123, poserpro, SKAN, Yahoo [Bot] and 9 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group