AutoHotkey Community

It is currently May 26th, 2012, 10:17 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: October 23rd, 2009, 6:52 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2009, 7:13 pm 
use settimer to loop the function and check the examples in help file about ImageSearch "if ErrorLevel"


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2009, 7:39 pm 
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?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2009, 7:45 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2009, 7:46 pm 
i mean
Code:
WinWaitActive, Title | Subtitle


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2009, 3:37 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2009, 4:57 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2009, 7:55 pm 
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! :D
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



Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2009, 8:19 pm 
u need to add "return" before the exitapp hotkey


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 25th, 2009, 3:06 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
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

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 6:00 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 6:41 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 6:42 am 
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
 


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: AndyJenk, hyper_, JSLover, Leef_me, patgenn123, rbrtryn, XstatyK and 71 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