AutoHotkey Community

It is currently May 26th, 2012, 11:20 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Macro Help
PostPosted: November 4th, 2008, 11:55 pm 
Offline

Joined: April 1st, 2008, 4:23 am
Posts: 12
Can I please get sample codes for the following:

-if "word" is detected on a page, then click "link"
(if click "link" doesn't work, then click [coordinates])

Also, to have this repeated at each new web page, until turned off.


I have already asked for help regarding the "word" condition, but haven't gotten help.


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

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
what browser

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2008, 12:15 am 
Offline

Joined: April 1st, 2008, 4:23 am
Posts: 12
any browser is fine with me. IE7 or FF.


does this, InStr(Haystack, Needle [, CaseSensitive = false, StartingPos = 1]):, have anything to do with it?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2008, 12:33 am 
Offline

Joined: April 1st, 2008, 4:23 am
Posts: 12
preferably IE7


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2008, 12:54 am 
Offline

Joined: April 1st, 2008, 4:23 am
Posts: 12
I would love to at least know the code for the 'search "word" command', please.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2008, 1:48 am 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
hassoun wrote:
does this, InStr(Haystack, Needle [, CaseSensitive = false, StartingPos = 1]):, have anything to do with it?
not unless you have devised a way to get the html
Code:
COM_CoInitialize()
OnExit,kill
handle:=iWeb_getwin("page title")
F6:
broke=
Loop
{
iWeb_clickText(handle,"some text you want to click")
iWeb_complete(handle)
if broke
break
}
Return
kill:
COM_CoUninitialize()
ExitApp
F7:
broke=1
Return
iWeb_getwin(t)
{
   psh   :=   COM_CreateObject("Shell.Application")
   psw   :=   COM_Invoke(psh,   "Windows")
   Loop, %   COM_Invoke(psw,   "Count")
   {
      LocationName   :=   COM_InvokeDeep(psw,"Item[" A_Index-1 "].LocationName")
       IfInString,LocationName,%t%
      {
         pwb         :=   COM_InvokeDeep(psw,"Item[" A_Index-1 "]")
         COM_Release(psw),   VarSetCapacity(psw,   0),   COM_Release(psh),   VarSetCapacity(psh,   0)
         Return   pwb   
      }
   }
   COM_Release(psw),   VarSetCapacity(psw,   0),   COM_Release(psh),   VarSetCapacity(psh,   0)
   Return   0
}

iWeb_complete(pwb)                  ;   returns bool for success or failure
{   
   If not pwb is Integer         ;   test to see if we have a valid interface pointer
      ExitApp                  ;   ExitApp if we dont
   loop 80                     ;   sets limit if itenerations to 40 seconds 80*500=40000=40 secs
   {   
      If (rdy:=COM_Invoke(pwb,"readyState") = 4)
         Return    1            ;   return success
      Sleep,500               ;   sleep half second between cycles
   }
   Return 0                  ;   lets face it if it got this far it failed
}                           ;   end complete
iWeb_DomWin(pwb)
{
   IID_IHTMLWindow2      := "{332C4427-26CB-11D0-B483-00C04FD90119}"
   Return            COM_QueryService(pwb,   IID_IHTMLWindow2,   IID_IHTMLWindow2)
}

iWeb_clickText(pwb,t)
{
/*********************************************************************
pwb   -   browser object
obj   -   object reference optionally a comma delimited list of references a name, id, or index of all value can be used
example of useage
the below will take a browser object and try get an link called username
clickText(pwb,"username")
This will cycle thru objects username pass and 3
clickText(pwb,"username,pass,3")

*/
   col      :=   COM_InvokeDeep(pWin   :=   iWeb_DomWin(pwb),   "document.links")
   If not col is Integer
   {
      COM_Release(col),   VarSetCapacity(col,   0),   COM_Release(pWin),   VarSetCapacity(pWin,   0)
      Return   0   
   }
   lnklen   :=   COM_Invoke(col,      "length")
   Loop,%   lnklen
   {
      If   itm      :=   COM_Invoke(col,"item", A_Index-1) is integer   ;if this fails there really isnt any need to do below
      {
         rslt   :=   COM_Invoke(itm,   "innerHTML")
         IfInString,rslt,%t%
         {
            COM_Invoke(itm,   "click")
            d=1
            COM_Release(itm),   VarSetCapacity(itm,   0)
            Break
         }
   ;~          release and clear out any objects
      }
         COM_Release(itm),   VarSetCapacity(itm,   0)
   }
   COM_Release(col),   VarSetCapacity(col,   0),   COM_Release(pWin),   VarSetCapacity(pWin,   0)
   Return   d
}
COM_InvokeDeep(obj, path, arg1="vT_NoNe", arg2="vT_NoNe", arg3="vT_NoNe", arg4="vT_NoNe", arg5="vT_NoNe", arg6="vT_NoNe", arg7="vT_NoNe", arg8="vT_NoNe")
{
   res := obj
   COM_AddRef(res) ; compensate for loop's Release()
   PathCt := 0
   Loop, Parse, Path, .
   {
     PathCt++
   }
   Loop, Parse, Path, ., ]
   {
      prop := A_LoopField
      value =
      StringGetPos, i, A_LoopField, [
      IfEqual, ErrorLevel, 0 ; contains index
      {
         StringLeft, prop, A_LoopField, %i%
         StringMid, value, A_LoopField, % i+2
      }
      If (value != "") ; contains index or parameter passed to a method, enclosed in "[]"
      {
         If (prop = "item") or (RegExMatch(value, "^[0-9]+$") = false) ; "item" already specified, or method call
         {
            If (A_Index < PathCt)
               propobj := COM_Invoke(res, prop, value)
            Else
               propobj := COM_Invoke(res, prop, value, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
            COM_Release(res),   VarSetCapacity(res,      0)
            res := propobj
         }
         Else
         {
            propobj := COM_Invoke(res, prop)
            If (A_Index < PathCt)
               itemobj := COM_Invoke(propobj, "Item", value)
            Else
               itemobj := COM_Invoke(propobj, "Item", value, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
            COM_Release(res),   VarSetCapacity(res,      0)
            COM_Release(propobj),   VarSetCapacity(propobj,      0)
            res := itemobj
         }
      }
      Else
      {
         If (A_Index < PathCt)
            propobj := COM_Invoke(res, prop)
         Else
         {
         sParams   := 12345678
         int:=False
         Loop,   Parse,   sParams
            If   arg%A_LoopField% is Integer
            {
               int:=true
               Break
            }
         If int
         {   
            Loop,   Parse,   sParams
            {   
                  If   (arg%A_LoopField% == "vT_NoNe")
                  {   
                     arg%A_LoopField% := ""
                     VT_BSTR%A_LoopField%:=""
                  }
                  Else
                     VT_BSTR%A_LoopField%:=8
            }
            propobj := COM_Invoke_(res, prop, VT_BSTR1,arg1,VT_BSTR2,arg2, VT_BSTR3,arg3, VT_BSTR4,arg4, VT_BSTR5,arg5, VT_BSTR6,arg6, VT_BSTR7,arg7, VT_BSTR8,arg8)
         }
         Else
            propobj := COM_Invoke(res, prop, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
       }
         COM_Release(res),   VarSetCapacity(res,      0)
         res := propobj
      }
      if !res ; no sense in continuing - object not found (returns 0 or null)
         break
   }
   Return res
}
need the COM library from my SIG (thanks Sean) 8)

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2008, 2:55 am 
Offline

Joined: April 1st, 2008, 4:23 am
Posts: 12
That is wonderful! Where is the field to put in the text to search? Also, why does it require involving COM? Anyway, that is not a problem.

So, say I want 5 different clicks depending on 5 different "words":

"a" click "1"
"b" click "2"
"c" click "3"
"d" click "4"
"e" click "5"


"f" then launch file from computer "alert.mp3"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2008, 3:39 am 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
hassoun wrote:
So, say I want 5 different clicks depending on 5 different "words":

"a" click "1"
"b" click "2"
"c" click "3"
"d" click "4"
"e" click "5"


"f" then launch file from computer "alert.mp3"
I just showed you how. INO you could just as easily change the loop to a parse
Code:
COM_CoInitialize()
OnExit,kill
handle:=iWeb_getwin("page title")
F6:
broke=
listoftext=abcdef
Loop,parse,listoftext ; each character will be parsed as a string
{
iWeb_clickText(handle,A_LoopField)
iWeb_complete(handle)
if broke
break
}
run, alert.mp3
Return
kill:
COM_CoUninitialize()
ExitApp
F7:
broke=1
Return

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2008, 4:36 am 
Offline

Joined: April 1st, 2008, 4:23 am
Posts: 12
I don't think this is working. I want the script to work for whole words and not just single letters.


If there is the word "apple", then "1apple" will be clicked
"banana", then "1banana" will be clicked
"cattle", then "1cattle" will be clicked
"danger", the "1danger" will be clicked
"elephant", then "1elephant will be clicked"

if the word "break" is found on the page, then "alert.mp3" is launched



also, sorry for being a bit thick


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2008, 7:24 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
you really have 2 choices here
show me actual list and page example or learn more about parsing loops from the help file

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: 0x150||ISO, BrandonHotkey, Yahoo [Bot] and 53 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