Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Image search and click on image


  • Please log in to reply
12 replies to this topic
Confused
  • Guests
  • Last active:
  • Joined: --
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.
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.

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


  • Guests
  • Last active:
  • Joined: --
use settimer to loop the function and check the examples in help file about ImageSearch "if ErrorLevel"

Confused
  • Guests
  • Last active:
  • Joined: --

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?

  • Guests
  • Last active:
  • Joined: --
i dont see any use for these, u can delete them
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
WinWaitActivate, Title | Subtitle


  • Guests
  • Last active:
  • Joined: --
i mean
WinWaitActive, Title | Subtitle


Confused
  • Guests
  • Last active:
  • Joined: --
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?

#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


  • Guests
  • Last active:
  • Joined: --
WinWaitActive is for waiting, it wont activiate ur brower and perform an imagesearch

which means, this 2 lines dont make sense at all
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

Confused
  • Guests
  • Last active:
  • Joined: --

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.

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



  • Guests
  • Last active:
  • Joined: --
u need to add "return" before the exitapp hotkey

MasterFocus
  • Moderators
  • 4322 posts
  • Last active:
  • Joined: 08 Apr 2009

add "return" before the exitapp hotkey

; ...
; ...
If ( ErrorLevel = 2 )
  MsgBox Could not conduct the search.
Else [color=darkred]If ErrorLevel = 0[/color]
  [color=darkred]Click %imageX%, %imageY%, left[/color]
[color=red]Return[/color]

^1:: exitapp


Confused
  • Guests
  • Last active:
  • Joined: --
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.
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


  • Guests
  • Last active:
  • Joined: --
check the errorlevel
if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1 ; [color=red]<---[/color]
    Return
else
    Sleep 300
    Click %imageX%, %imageY%, left
Return


  • Guests
  • Last active:
  • Joined: --
also i notice an error
if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    Return
else
[color=red]{[/color]
    Sleep 300
    Click %imageX%, %imageY%, left
[color=red]}[/color]
Return