Moderators SmOke_N Posted January 6, 2015 Moderators Share Posted January 6, 2015 I feel like I'm in a confessional... Please forgive me, I think it's been 8 years since I've asked a question in the GH&S. I've been putting together a helpful array of udf's for MSHTML events. I've come across two event interface names that are not cooperating. Of all the reading I've done, it looks like most of them directly interact with the element through the IID but I'll be damned if I can figure it out correctly. Here are the links: http://msdn.microsoft.com/en-us/library/aa769636(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/aa743143(v=vs.85).aspx Anyone have a bone to throw (Debug code below)? expandcollapse popup#include <IE.au3> #include <Debug.au3> _DebugSetup() _DebugCOMError() _Example() ConsoleWrite(@error & ":" & @extended & @CRLF) Func _Example() Local $oIE = _IECreate() If Not IsObj($oIE) Then Return SetError(1, 0, 0) EndIf _IEDocWriteHTML($oIE, Example_GetHTML()) Local $oDoc = $oIE.document Local $oPW = $oDoc.parentWindow Local $oForm = _IEFormGetCollection($oIE, 0) Local $oFName = _IEGetObjByName($oIE, "firstname") Local $oLName = _IEGetObjByName($oIE, "lastname") Local $oEmail = _IEGetObjByName($oIE, "email") Local $oMSex = _IEGetObjByName($oIE, "msex") Local $oFSex = _IEGetObjByName($oIE, "fsex") Local $oSubmit = _IEGetObjById($oIE, "submit2") Local $oReset = _IEGetObjById($oIE, "reset") Local $aOTmp[] = [$oIE, $oDoc, $oPW, $oForm, $oFName, $oLName, _ $oEmail, $oMSex, $oFSex, $oSubmit, $oReset] Local $oEvent For $i = 0 To UBound($aOTmp) - 1 $oEvent = ObjEvent($aOTmp[$i], "__Example_", "HTMLElementEvents2") If Not @error Then ConsoleWrite("Found Element Object: " & $i & @CRLF) ExitLoop EndIf $oEvent = ObjEvent($aOTmp[$i], "__Example_", "HTMLControlElementEvents2") If Not @error Then ConsoleWrite("Found Control Element Object: " & $i & @CRLF) ExitLoop EndIf Next While WinExists(HWnd($oIE.hwnd)) Sleep(10) WEnd _IEQuit($oIE) EndFunc Func __Example_onClick(ByRef $oObj) Example_Handler($oObj) EndFunc Func Example_Handler(ByRef $oObj) ConsoleWrite($oObj.type & @CRLF) EndFunc Func Example_GetHTML() Local $sHTML = "" $sHTML &= "0x3C21444F43545950452068746D6C3E0D0A3C68746D6C3E0D0A3C626F64" $sHTML &= "793E0D0A0D0A203C464F524D206E616D653D22736F6D65666F726D223E0D" $sHTML &= "0A202020203C503E0D0A202020204669727374206E616D653A203C494E50" $sHTML &= "555420747970653D227465787422206E616D653D2266697273746E616D65" $sHTML &= "223E3C42523E0D0A202020204C617374206E616D653A203C494E50555420" $sHTML &= "747970653D227465787422206E616D653D226C6173746E616D65223E3C42" $sHTML &= "523E0D0A20202020656D61696C3A203C494E50555420747970653D227465" $sHTML &= "787422206E616D653D22656D61696C223E3C42523E0D0A202020203C494E" $sHTML &= "50555420747970653D22726164696F22206E616D653D226D736578222076" $sHTML &= "616C75653D224D616C65223E204D616C653C42523E0D0A202020203C494E" $sHTML &= "50555420747970653D22726164696F22206E616D653D2266736578222076" $sHTML &= "616C75653D2246656D616C65223E2046656D616C653C42523E0D0A202020" $sHTML &= "203C494E5055542069643D227375626D6974322220747970653D22737562" $sHTML &= "6D6974222076616C75653D2253656E64223E203C494E5055542069643D22" $sHTML &= "72657365742220747970653D227265736574223E0D0A202020203C2F503E" $sHTML &= "0D0A203C2F464F524D3E0D0A0D0A3C2F626F64793E0D0A3C2F68746D6C3E" Return BinaryToString($sHTML) EndFunc I'm not familiar with the ObjCreateInterface as of yet, but I have a feeling, before this is over, I will be (that seems to be the direction the code is heading me in from what I've read). mLipok 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 8, 2015 Author Moderators Share Posted January 8, 2015 HTMLElementEvents: "This dispinterface provides a connection point so that an application or control can intercept events fired by an element." The description is pretty misleading IMO. It appears to only work with non-functional elements (eg. div, p, span). But at least it's working now: expandcollapse popup#include <IE.au3> _Example() ConsoleWrite(@error & ":" & @extended & @CRLF) Func _Example() Local $oIE = _IECreate() If Not IsObj($oIE) Then Return SetError(1, 0, 0) EndIf _IEDocWriteHTML($oIE, Example_GetHTML()) Local $oDiv = _IEGetObjById($oIE, "mydiv") Local $oPar = _IETagNameGetCollection($oIE, "p", 0) Local $oDivEvent = ObjEvent($oDiv, "__Example_", "HTMLElementEvents2") Local $oParEvent = ObjEvent($oPar, "__Example_", "HTMLElementEvents2") While WinExists(HWnd($oIE.hwnd)) Sleep(10) WEnd _IEQuit($oIE) EndFunc Func __Example_onmousemove(ByRef $oObj) Example_Handler($oObj) EndFunc Func Example_Handler(ByRef $oObj) Local $sEventType = String($oObj.type) If $sEventType Then ConsoleWrite($sEventType & @CRLF) EndFunc Func Example_GetHTML() Local $sHTML = "" $sHTML &= "0x3C21444F43545950452068746D6C3E0D0A3C68746D6C3E0D0A3C626F64" $sHTML &= "793E0D0A0D0A203C4469762069643D226D79646976223E0D0A2020203C46" $sHTML &= "4F524D206E616D653D22736F6D65666F726D223E0D0A2020202020203C50" $sHTML &= "3E0D0A2020202020204669727374206E616D653A203C494E505554207479" $sHTML &= "70653D227465787422206E616D653D2266697273746E616D65223E3C4252" $sHTML &= "3E0D0A2020202020204C617374206E616D653A203C494E50555420747970" $sHTML &= "653D227465787422206E616D653D226C6173746E616D65223E3C42523E0D" $sHTML &= "0A202020202020656D61696C3A203C494E50555420747970653D22746578" $sHTML &= "7422206E616D653D22656D61696C223E3C42523E0D0A2020202020203C49" $sHTML &= "4E50555420747970653D22726164696F22206E616D653D226D7365782220" $sHTML &= "76616C75653D224D616C65223E204D616C653C42523E0D0A202020202020" $sHTML &= "3C494E50555420747970653D22726164696F22206E616D653D2266736578" $sHTML &= "222076616C75653D2246656D616C65223E2046656D616C653C42523E0D0A" $sHTML &= "2020202020203C494E5055542069643D227375626D697432222074797065" $sHTML &= "3D227375626D6974222076616C75653D2253656E64223E203C494E505554" $sHTML &= "2069643D2272657365742220747970653D227265736574223E0D0A202020" $sHTML &= "2020203C2F503E0D0A2020203C2F464F524D3E0D0A203C2F4469763E0D0A" $sHTML &= "3C2F626F64793E0D0A3C2F68746D6C3E" Return BinaryToString($sHTML) EndFunc Unfortunately, I am still not getting HTMLControlElementEvents2 working. But for those that run across this, you can at least understand HTMLElementEvents2. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
JohnOne Posted January 8, 2015 Share Posted January 8, 2015 Besides starting IE and writing the HTML, code does nothing here, nothing is written to the console and the script does not end when I close the IE window. Win 7 32 IE 11, without breaking update installed. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
kylomas Posted January 8, 2015 Share Posted January 8, 2015 (edited) Works on Win7 x64 IE9... edit: If I may, why did you represent the HTML as a hex string? Edited January 8, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 8, 2015 Author Moderators Share Posted January 8, 2015 (edited) I always do my code, binary, strings that way. Just a personal preference. Most often it results in less lines. Edit: Not to mention I never have to worry about quotes that exist within the string . Edited January 8, 2015 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Malkey Posted January 8, 2015 Share Posted January 8, 2015 The HTML document appears in the browser and is reacting the the mouse. But for me, the script is not getting past the _IEDocWriteHTML function. Within the _IEDocWriteHTML function, it appears the script is stopped by _IELoadWait waiting for the browser page to complete loading. Using _IEPropertySet($oIE, "innerhtml", Example_GetHTML()) instead of _IEDocWriteHTML($oIE, Example_GetHTML()) and the script works fine - both events appear to be working. Link to comment Share on other sites More sharing options...
JohnOne Posted January 8, 2015 Share Posted January 8, 2015 Must just be this scabby old laptop. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted January 12, 2015 Share Posted January 12, 2015 Besides starting IE and writing the HTML, code does nothing here, nothing is written to the console and the script does not end when I close the IE window. Win 7 32 IE 11, without breaking update installed. Yes, it was the crappy laptop I was using. this works fine for mouseover and mousemove. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 12, 2015 Author Moderators Share Posted January 12, 2015 I still don't have HTMLControlElementEvents working unfortunately. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now