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 

Image search and click on image

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





PostPosted: Fri Oct 23, 2009 5:52 pm    Post subject: Image search and click on image Reply with quote

Just found AutoHotkey and I love it! Its so powerful.
Problem is I'm not good with computer programming. I can’t give too much details about the app as the Dev’s are pretty sharp and will ban any account even looking like a script/bot, hence the use of mouse clicks.

Script purpose: To activate two windows and click on the image which appears only every 15 minutes (pending lag/etc). The script will detect the appearance of the image in the two windows and “hijack” the mouse to activate the two windows and click on the image on both these two windows and return control to user in an endless loop.

This is the current code which clicks every 1 min on the preset positions.
Code:
Loop 14400
{
WinWait, Title | Subtitle - Mozilla Firefox,
IfWinNotActive, Title | Subtitle - Mozilla Firefox, , WinActivate, Title | Subtitle - Mozilla Firefox,
WinActivate, Title | Subtitle- Mozilla Firefox,
WinWaitActive, Title | Subtitle- Mozilla Firefox,
MouseClick, left,  435,  339, 2, 0
Sleep, 200
WinWait, Title | Subtitle- Google Chrome,
IfWinNotActive, Title | Subtitle- Google Chrome, , WinActivate, Title | Subtitle- Google Chrome,
WinActivate, Title | Subtitle- Google Chrome,
WinWaitActive, Title | Subtitle- Google Chrome,
MouseClick, left,  487,  316, 2, 0
MouseMove, 400, 400
Sleep, 60000
}

^1::
{
exitapp
}



Image search works but it doesn't loop indefinitely and clicks on current mouse position if image is not found.

Code:

CoordMode, Pixel, Screen
ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, C:\Documents and Settings\Hansel\My Documents\Games\Horn.bmp ; the smaller and more precise the  image the better, you can use printscreen and mspaint to make these easily enough.
WinWait, Title | Subtitle - Mozilla Firefox,
IfWinNotActive, Title | Subtitle - Mozilla Firefox, , WinActivate, Title | Subtitle - Mozilla Firefox,
WinActivate, Title | Subtitle - Mozilla Firefox,
WinWaitActive, Title | Subtitle - Mozilla Firefox,
WinWait, Title | Subtitle - Google Chrome,
IfWinNotActive, Title | Subtitle - Google Chrome, , WinActivate, Title | Subtitle - Google Chrome,
WinActivate, Title | Subtitle - Google Chrome,
WinWaitActive, Title | Subtitle - Google Chrome,
Click %imageX%, %imageY%, left
Sleep 200
Click %imageX%, %imageY%, left

^1:: exitapp
Back to top
Guest






PostPosted: Fri Oct 23, 2009 6:13 pm    Post subject: Reply with quote

use settimer to loop the function and check the examples in help file about ImageSearch "if ErrorLevel"
Back to top
Confused
Guest





PostPosted: Fri Oct 23, 2009 6:39 pm    Post subject: Reply with quote

Anonymous wrote:
use settimer to loop the function and check the examples in help file about ImageSearch "if ErrorLevel"


Should IfWinActivate and related commands be inside ErrorLevel or outside?
Back to top
Guest






PostPosted: Fri Oct 23, 2009 6:45 pm    Post subject: Reply with quote

i dont see any use for these, u can delete them
Code:
WinWait, Title | Subtitle - Mozilla Firefox,
IfWinNotActive, Title | Subtitle - Mozilla Firefox, , WinActivate, Title | Subtitle - Mozilla Firefox,
WinActivate, Title | Subtitle - Mozilla Firefox,
WinWaitActive, Title | Subtitle - Mozilla Firefox,
WinWait, Title | Subtitle - Google Chrome,
IfWinNotActive, Title | Subtitle - Google Chrome, , WinActivate, Title | Subtitle - Google Chrome,
WinActivate, Title | Subtitle - Google Chrome,
WinWaitActive, Title | Subtitle - Google Chrome, 


but add this line back at the top before imagesearch
Code:
WinWaitActivate, Title | Subtitle
Back to top
Guest






PostPosted: Fri Oct 23, 2009 6:46 pm    Post subject: Reply with quote

i mean
Code:
WinWaitActive, Title | Subtitle
Back to top
Confused
Guest





PostPosted: Sat Oct 24, 2009 2:37 am    Post subject: Reply with quote

What works:
1. Clicks on image when appears.


What doesn't work:
1. Clicks on image at any random window which image appears, not on both windows as intended.
2. Clicks take time about one minute before responding.
3. Does not activate both windows to search for image.

What am I doing wrong?

Code:
#Persistent
SetTimer, Searchclick, 1000
return

Searchclick:
WinWaitActive, Title | Subtitle - Mozilla Firefox,
WinWaitActive, Title | Subtitle - Google Chrome,
CoordMode, Pixel, Screen
ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, C:\Documents and Settings\Hansel\My

Documents\Games\Horn.bmp
if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    return
else
     Click %imageX%, %imageY%, left

^1:: exitapp
Back to top
Guest






PostPosted: Sat Oct 24, 2009 3:57 am    Post subject: Reply with quote

WinWaitActive is for waiting, it wont activiate ur brower and perform an imagesearch

which means, this 2 lines dont make sense at all
Code:
WinWaitActive, Title | Subtitle - Mozilla Firefox,
WinWaitActive, Title | Subtitle - Google Chrome,


it should be, Winactiviate browser 1, WinWaitActive browser 1, perform imagesearch, Winactiviate another browser, WinWaitActive the another browser, perform imagesearch
Back to top
Confused
Guest





PostPosted: Sat Oct 24, 2009 6:55 pm    Post subject: Reply with quote

Anonymous wrote:

it should be, Winactiviate browser 1, WinWaitActive browser 1, perform imagesearch, Winactiviate another browser, WinWaitActive the another browser, perform imagesearch


Thanks for the help! Very Happy
Worked out great, except one major problem, the script if set to launch every 15 minutes only began activating Window1/Window2 and searching for the two images.

I added the 1st set of codes to launch an intital set of clicks, but I can't seem to get the rest of the code to work if SetTimer is set > 60,000.

Assistance would be appreciated.

Code:
WinActivate, MouseHunt on Facebook | Hunter's Camp - Mozilla Firefox,
WinWaitActive, MouseHunt on Facebook | Hunter's Camp - Mozilla Firefox,
CoordMode, Pixel, Screen
ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, C:\Documents and Settings\Hansel\My Documents\Games\Horn.bmp
Click %imageX%, %imageY%, left
Sleep, 300
WinActivate, MouseHunt on Facebook | Hunter's Camp - Google Chrome,
WinWaitActive, MouseHunt on Facebook | Hunter's Camp - Google Chrome,
ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, C:\Documents and Settings\Hansel\My Documents\Games\Horn.bmp
Click %imageX%, %imageY%, left


#Persistent
SetTimer, Searchclick, 900000
return

Searchclick:
WinActivate, MouseHunt on Facebook | Hunter's Camp - Mozilla Firefox,
WinWaitActive, MouseHunt on Facebook | Hunter's Camp - Mozilla Firefox,
CoordMode, Pixel, Screen
ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, C:\Documents and Settings\Hansel\My Documents\Games\Horn.bmp
WinActivate, MouseHunt on Facebook | Hunter's Camp - Google Chrome,
WinWaitActive, MouseHunt on Facebook | Hunter's Camp - Google Chrome,
ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, C:\Documents and Settings\Hansel\My Documents\Games\Horn.bmp
if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    return
else
     Click %imageX%, %imageY%, left


^1:: exitapp

Back to top
Guest






PostPosted: Sat Oct 24, 2009 7:19 pm    Post subject: Reply with quote

u need to add "return" before the exitapp hotkey
Back to top
MasterFocus



Joined: 08 Apr 2009
Posts: 882
Location: Rio de Janeiro - RJ - Brasil

PostPosted: Sun Oct 25, 2009 2:06 am    Post subject: Reply with quote

Anonymous wrote:
add "return" before the exitapp hotkey

Code:
; ...
; ...
If ( ErrorLevel = 2 )
  MsgBox Could not conduct the search.
Else If ErrorLevel = 0
  Click %imageX%, %imageY%, left
Return

^1:: exitapp

_________________
Antonio França
aka MasterFocus aka Tunis
+ My AHK stuff: ~MasterFocus
+ AHK @ irc.freenode.net: #ahk
Contact: PM only !
Back to top
View user's profile Send private message
Confused
Guest





PostPosted: Tue Oct 27, 2009 5:00 am    Post subject: Reply with quote

New problem, sometimes the page fails to load properly.
How do I write in an
IF "image not present in window"
Else Send {F5}?

with the existing lines written in? I'm lost and don't know where to start... So sorry to trouble everyone again.

Current code.
Code:
MouseMove, 400, 400
WinActivate, MouseHunt on Facebook | Hunter's Camp - Mozilla Firefox,
WinWaitActive, MouseHunt on Facebook | Hunter's Camp - Mozilla Firefox,
CoordMode, Pixel, Screen
ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, C:\Documents and Settings\Hansel\My Documents\Games\Horn.bmp
Sleep, 300
Click %imageX%, %imageY%, left
WinActivate, MouseHunt on Facebook | Hunter's Camp - Google Chrome,
WinWaitActive, MouseHunt on Facebook | Hunter's Camp - Google Chrome,
ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, C:\Documents and Settings\Hansel\My Documents\Games\Horn.bmp
Sleep, 300
Click %imageX%, %imageY%, left



#Persistent
SetTimer, Searchclick, 300000
return

Searchclick:
CoordMode, Pixel, Screen
WinActivate, MouseHunt on Facebook | Hunter's Camp - Mozilla Firefox,
WinWaitActive, MouseHunt on Facebook | Hunter's Camp - Mozilla Firefox,
ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, C:\Documents and Settings\Hansel\My Documents\Games\Horn.bmp
WinActivate, MouseHunt on Facebook | Hunter's Camp - Google Chrome,
WinWaitActive, MouseHunt on Facebook | Hunter's Camp - Google Chrome,
ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, C:\Documents and Settings\Hansel\My Documents\Games\Horn.bmp
if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    Return
else
    Sleep 300
    Click %imageX%, %imageY%, left
Return

^1:: exitapp
Back to top
Guest






PostPosted: Tue Oct 27, 2009 5:41 am    Post subject: Reply with quote

check the errorlevel
Code:
if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1 ; <---
    Return
else
    Sleep 300
    Click %imageX%, %imageY%, left
Return
Back to top
Guest






PostPosted: Tue Oct 27, 2009 5:42 am    Post subject: Reply with quote

also i notice an error
Code:

if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    Return
else
{
    Sleep 300
    Click %imageX%, %imageY%, left
}
Return
 
Back to top
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