 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
hassoun
Joined: 01 Apr 2008 Posts: 12
|
Posted: Tue Nov 04, 2008 10:55 pm Post subject: Macro Help |
|
|
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. |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 2294 Location: Louisville KY USA
|
|
| Back to top |
|
 |
hassoun
Joined: 01 Apr 2008 Posts: 12
|
Posted: Tue Nov 04, 2008 11:15 pm Post subject: |
|
|
any browser is fine with me. IE7 or FF.
does this, InStr(Haystack, Needle [, CaseSensitive = false, StartingPos = 1]):, have anything to do with it? |
|
| Back to top |
|
 |
hassoun
Joined: 01 Apr 2008 Posts: 12
|
Posted: Tue Nov 04, 2008 11:33 pm Post subject: |
|
|
| preferably IE7 |
|
| Back to top |
|
 |
hassoun
Joined: 01 Apr 2008 Posts: 12
|
Posted: Tue Nov 04, 2008 11:54 pm Post subject: |
|
|
| I would love to at least know the code for the 'search "word" command', please. |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 2294 Location: Louisville KY USA
|
Posted: Wed Nov 05, 2008 12:48 am Post subject: |
|
|
| 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)  _________________ Basic Webpage Controls with JavaScript / COM - Tutorial by Jethrow
 |
|
| Back to top |
|
 |
hassoun
Joined: 01 Apr 2008 Posts: 12
|
Posted: Wed Nov 05, 2008 1:55 am Post subject: |
|
|
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" |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 2294 Location: Louisville KY USA
|
Posted: Wed Nov 05, 2008 2:39 am Post subject: |
|
|
| 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 |
_________________ Basic Webpage Controls with JavaScript / COM - Tutorial by Jethrow
 |
|
| Back to top |
|
 |
hassoun
Joined: 01 Apr 2008 Posts: 12
|
Posted: Mon Nov 17, 2008 3:36 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 2294 Location: Louisville KY USA
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|