AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: November 11th, 2009, 8:49 am 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2009, 9:15 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
You can use a loop or SetTimer for that.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2009, 6:58 pm 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2009, 7:57 pm 
Online

Joined: April 8th, 2009, 7:49 pm
Posts: 6068
Location: San Diego, California
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2009, 11:07 pm 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 12:34 am 
Online

Joined: April 8th, 2009, 7:49 pm
Posts: 6068
Location: San Diego, California
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. :cry:

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 1:21 am 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
I tried that one already and it ends up Breaking everytime, even if the window isn't there? what gives?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 2:01 am 
Online

Joined: April 8th, 2009, 7:49 pm
Posts: 6068
Location: San Diego, California
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 2:50 am 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 5:38 am 
Online

Joined: April 8th, 2009, 7:49 pm
Posts: 6068
Location: San Diego, California
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 6:35 am 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 6:46 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], hyper_, Leef_me, patgenn123, Pulover, rbrtryn, XstatyK and 20 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