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 

Quick PixelSearch question

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
4birds



Joined: 06 Mar 2008
Posts: 167

PostPosted: Wed Nov 11, 2009 7:49 am    Post subject: Quick PixelSearch question Reply with quote

I haven't been able to find a post on this problem although I don't doubt it's already in another post. If so, just direct me there.

I would like to search an area for a pixel. When it shows up I would like to mouseclick that pixel. Sometimes that pixel will be there and sometimes not.
Here's my current code
Code:

PixelSearch,OutputVarX,OutputVary, 360, 552, 392, 560, 0x000000, 3, Fast
if ErrorLevel
    MsgBox, That color was not found in the specified region.
else
Click, %OutputVarX%,%OutputVarY%
sleep, 100


Of course, right now, when the pixel is not there it'll throw up a message box. How do I keep a persistent "watch" out for the pixel as to send the mouseclick as soon as it pops up?
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5044
Location: the tunnel(?=light)

PostPosted: Wed Nov 11, 2009 8:15 am    Post subject: Reply with quote

You can use a loop or SetTimer for that.
_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
4birds



Joined: 06 Mar 2008
Posts: 167

PostPosted: Wed Nov 11, 2009 5:58 pm    Post subject: Reply with quote

If I'm running a loop, how do I exit it if a particular window pops up

current code
Code:

^1::
loop
{
ImageSearch, OutputVara, OutputVarb, 648, 430, 693, 464, C:\test.png
sleep, 100
Click %OutputVara% %OutputVarb%
sleep, 500
PixelSearch,OutputVarX,OutputVary, 360, 552, 392, 560, 0x000000, 3, Fast
sleep, 500
Click, %OutputVarX%,%OutputVarY%
sleep, 500
ImageSearch, OutputVarM, OutputVarN, 654, 341, 866, 525, C:\save.png
sleep, 500
Click %OutputVarM% %OutputVarN%
      IfWinexist, https://www.website.com - External Launch - Microsoft Internet Explorer
       ???
}
space::pause
exit app


It's god awful code, but anyways. Once I click the image for save.png, that brings up an external webpage (which it's suppose to do). Once this webapge exists I want the script to stop, pause or kill.
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Wed Nov 11, 2009 6:57 pm    Post subject: Reply with quote

http://www.autohotkey.com/docs/commands/Loop.htm

Perform a series of commands repeatedly: either the specified number of times or until break is encountered.

A common use of this command is an infinite loop that uses the break command somewhere in the loop's body to determine when to stop the loop.
Back to top
View user's profile Send private message
4birds



Joined: 06 Mar 2008
Posts: 167

PostPosted: Wed Nov 11, 2009 10:07 pm    Post subject: Reply with quote

I tried this, but the loop continues on even though the window has popped up and exists.
Code:

^1::
loop
{
ImageSearch, OutputVara, OutputVarb, 648, 430, 693, 464, C:\test.png
sleep, 100
Click %OutputVara% %OutputVarb%
sleep, 500
PixelSearch,OutputVarX,OutputVary, 360, 552, 392, 560, 0x000000, 3, Fast
sleep, 500
Click, %OutputVarX%,%OutputVarY%
sleep, 500
ImageSearch, OutputVarM, OutputVarN, 654, 341, 866, 525, C:\save.png
sleep, 500
Click %OutputVarM% %OutputVarN%
Loop
{
      IfWinexist, https://www.website.com - External Launch - Microsoft Internet Explorer
       Break
     }
}
space::pause
exit app


what am I doing wrong?
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Wed Nov 11, 2009 11:34 pm    Post subject: Reply with quote

Flight4birds wrote:
I tried this, but the loop continues on even though the window has popped up and exists.


what am I doing wrong?


All you needed to do was replace "???" with "Break". But you added a whole nother loop. Crying or Very sad

Code:

^1::
loop
{
ImageSearch, OutputVara, OutputVarb, 648, 430, 693, 464, C:\test.png
sleep, 100
Click %OutputVara% %OutputVarb%
sleep, 500
PixelSearch,OutputVarX,OutputVary, 360, 552, 392, 560, 0x000000, 3, Fast
sleep, 500
Click, %OutputVarX%,%OutputVarY%
sleep, 500
ImageSearch, OutputVarM, OutputVarN, 654, 341, 866, 525, C:\save.png
sleep, 500
Click %OutputVarM% %OutputVarN%
      IfWinexist, https://www.website.com - External Launch - Microsoft Internet Explorer
       Break
}
space::pause
exit app
Back to top
View user's profile Send private message
4birds



Joined: 06 Mar 2008
Posts: 167

PostPosted: Thu Nov 12, 2009 12:21 am    Post subject: Reply with quote

I tried that one already and it ends up Breaking everytime, even if the window isn't there? what gives?
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Thu Nov 12, 2009 1:01 am    Post subject: Reply with quote

Flight4birds wrote:
I tried that one already and it ends up Breaking everytime, even if the window isn't there? what gives?

Is a window that matches that pattern open on your machine?
By 'open' I don't mean, active and being viewed. It could be minimized.
Back to top
View user's profile Send private message
4birds



Joined: 06 Mar 2008
Posts: 167

PostPosted: Thu Nov 12, 2009 1:50 am    Post subject: Reply with quote

Actually, here's the code, I just omited some lines that I thought were irrelavent.
Code:

1::
loop
{
ImageSearch, OutputVara, OutputVarb, 648, 430, 693, 464, C:\test.png
sleep, 100
Click %OutputVara% %OutputVarb%
sleep, 500
IfWinexist, Microsoft Internet Explorer
Winkill, Microsoft Internet Explorer
sleep, 500
PixelSearch,OutputVarX,OutputVary, 360, 552, 392, 560, 0x000000, 3, Fast
sleep, 500
Click, %OutputVarX%,%OutputVarY%
sleep, 500
ImageSearch, OutputVarM, OutputVarN, 654, 341, 866, 525, C:\save.png
sleep, 500
Click %OutputVarM% %OutputVarN%
 
IfWinexist, https://www.website.com - External Launch - Microsoft Internet Explorer
  Break
    sleep, 2000
}
space::pause
exit app


When I run this script, a message box may appear when I hit the test.png image. If so, I use WinKill to get rid of it. But the second WinExist in the code comes after that window is already gone. And yet it still puts a break in there.
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Thu Nov 12, 2009 4:38 am    Post subject: Reply with quote

This is my 4th post to you in approximately 9 hours, seemingly on the same subject.

My first post was a reference to the answer you needed.
Through two other posts I have attempted to help, but I have failed to help solve your problem.

Now I read this:
Quote:
Actually, here's the code, I just omited some lines that I thought were irrelavent.

I fear that I can't guide you or help you because you pick and choose what to share.
You omit important facts, eg. that a window pops up and you kill it and that another may come as well.

Perhaps the task is too complex for Ahk, or for me, or for you; I don't know. I can't judge because you decide what to share.

If you want my continued help I need the following: A better description of what you are really facing.

Your code shows you find and click on an image, find & click on a pixel , then find and click on an image once again. Then your loop repeats.
Somewhere in there you get other windows and you kill one, but want to stop looping when the other window shows. Why do you need loop as written?
Back to top
View user's profile Send private message
4birds



Joined: 06 Mar 2008
Posts: 167

PostPosted: Thu Nov 12, 2009 5:35 am    Post subject: Reply with quote

Leef_Me,
my apologies. Sometimes I just think everyone is privy to the same track that my brain is going on. I apologize for being unclear.

So I'll give you a run down and thinking behind my script.

1. When I click the image test.png, it refreshes a frame in another part of the webpage.
2. if the the frame contains no data, a message box pops up saying somethinng to the effect of "No data available"
3. I then kill that message box(I guess at this point, I could have it start back at the beggining of the loop).
4. To check if data is in the frame I have to do a pixelsearch( it sounds weird but it's a secure work webapge that has a frame that is loaded by AJAX. through all my ahk research and trial and error, I've been unable to scrape any text off the frame. I can do a pixelsearch though to see if text is there. It's primitive, but it works.)
5.So after hitting the test.png, which refreshes the frame, if data is in the frame, no message box will come up. Pixelsearch then scans the frame and clicks the top row in the frame.
6. By clicking the top row in this frame, it illuminates a 2cd image on the webpage. It then searches for that image to click.
7. By clicking that final image save.png, another window pops up asking me if I really want to save. This is why I want the break in the loop. Once this question box comes up I don't want the loop to scan anymore.

Code:


1::
loop
{
ImageSearch, OutputVara, OutputVarb, 648, 430, 693, 464, C:\test.png
sleep, 100
Click %OutputVara% %OutputVarb%
sleep, 500
[
IfWinexist, Microsoft Internet Explorer
Winkill, Microsoft Internet Explorer
sleep, 500
PixelSearch,OutputVarX,OutputVary, 360, 552, 392, 560, 0x000000, 3, Fast
sleep, 500
Click, %OutputVarX%,%OutputVarY%
sleep, 500
ImageSearch, OutputVarM, OutputVarN, 654, 341, 866, 525, C:\save.png
sleep, 500
Click %OutputVarM% %OutputVarN%
 
IfWinexist, https://www.website.com - External Launch - Microsoft Internet Explorer
  Break
    sleep, 2000
}
space::pause
exit app

It really is a screwy loop script, but it's the only way to automate to check for the data in this frame and then click the save.png image to save it.
I know it hard to paint a picture when you don't know what the website is. The best way I can describe it is that it's like a JAVA applet. So while you can mouseclick buttons, you can't really scape the visual data off.
I hope I'm not frustrating you too much. If so, just let this post drift down the forum stream.
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5044
Location: the tunnel(?=light)

PostPosted: Thu Nov 12, 2009 5:46 am    Post subject: Reply with quote

Put the IfWinExist at the top so it will break the loop before it proceeds with the check:

Code:
1::
loop
{
  IfWinexist, https://www.website.com - External Launch - Microsoft Internet Explorer
    Break

  ImageSearch, oVarA, oVarB, 648, 430, 693, 464, C:\test.png
  if !ErrorLevel ; if ErrorLevel is set to 0
    Click %oVarA% %oVarB%
  sleep, 500
  IfWinExist, Microsoft Internet Explorer
  {
    Winkill, Microsoft Internet Explorer
    WinWaitClose, Microsoft Internet Explorer
  }
  sleep, 500
  PixelSearch,oVarX,oVarY, 360, 552, 392, 560, 0x000000, 3, Fast
  If !ErrorLevel
    Click, %oVarX%,%oVarY%
  sleep, 500
  ImageSearch, oVarM, oVarN, 654, 341, 866, 525, C:\save.png
  if !ErrorLevel
    Click %oVarM% %oVarN%
}
return
space::pause
exit app

_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
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