Jump to content

Recommended Posts

Posted

it works great for me.

 

Can you give more details?

 

Saludos

Posted (edited)
attach("http://www.dir.bg/")
$test=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents")
$test2=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2")
While 1
 Sleep(10)
WEnd

Func IEEvent_($event)
MsgBox( 0,"","")
EndFunc

This code should pop up a msg box every time an IE event is fired. I dont get any popup when i do actions on the webpage.

@EDIT Attach is a custom function using IEATTACH - that part works , i tested it.

Edited by Juvigy
ADD
Posted

You must define the event to be handled. 

 

#include <MsgBoxConstants.au3>
#include <IE.au3>


Local $oIE = _IECreate("", 0, 1, 0)
; Custom sink object
Local $oIEEvents = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents2")

_IENavigate($oIE, "www.autoitscript.com")
While True
    Sleep(30)
WEnd


; BeforeNavigate2 method definition
Func _IEEvent_BeforeNavigate2($oIEpDisp, $sIEURL, $iIEFlags, $sIETargetFrameName, $sIEPostData, $iIEHeaders, $bIECancel)
    MsgBox(0, "", "Event")
EndFunc   ;==>_IEEvent_BeforeNavigate2

Saludos

  • 8 months later...
Posted

This is from the help file :

  Quote

If you don't know (for some reason) the names of the events, you can add a UDF with only the prefix. In this example: Func IEEvent_($Eventname).
When an event is received and no IEEvent_ Eventname UDF exists, this function will be called instead and the name of the event will be placed in the variable $Eventname.

Expand  

Can someone please test it and advise if my error reproducer works ?

$test=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents")
$test2=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2")

Func IEEvent_($event)
    msgbox(0,"","")
End Func

Each event will popup a msg so you should see many msgs. I dont have any msg popups when testing this code!

Posted

doesn't works here...

where did you found those infos? I don't found that senetence in my AutoIt Help (I'm testing on AutoIt v. 3.3.14.2)

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted (edited)
  On 10/27/2016 at 10:28 PM, Chimp said:

where did you found those infos?

Expand  

Maybe in
Obj/COM Reference

in AutoIt HelpFile

  Quote

Click here to view the complete script.

Expand  

There is similar example:

Func IEEvent_($sEventName)
    ; This is an optional event function to catch non-defined events.
    ; The parameter contains the name of the event being called.
    GUICtrlSetData($g_idGUIEdit, "Uncatched event: " & $sEventName & @CRLF, "append")
EndFunc   ;==>IEEvent_

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

I removed that from AutoIt few years back. The feature was consuming too many resources and have been slowing down execution.
On top of that, the feature is senseless. You either know what you want to capture, or don't capture at all. Third option is just gay.

Unfortunately I missed the example script from the help file.

Edited by trancexx

♡♡♡

.

eMyvnE

Posted

Good to know.
So help file should be revised in this regard.

Thanks @trancexx for explanation.

mLipok

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

while experimenting with Obj events, I slammed into a wall...
I'm stucked on how to correctly refer the 'event' object within the event function in the AutoIt listing.
the commented line 79, should print coordinates of the mouse while mouse is moving on the web page, I get an error instead.
event.clientX and event.clientY should return the mouse coordinates,
see here ?? : https://msdn.microsoft.com/en-us/library/ms536947(v=vs.85).aspx
and/or here: ?? https://msdn.microsoft.com/en-us/library/ff975920(v=vs.85).aspx

what I'm doing wrong?

; We use a very simple GUI to show the results of our Events.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Global $g_idGUIEdit

Example()
Exit ; End of our Demo.

Func Example()
    Local $hGUIMain = GUICreate("Event Test", 1000, 600)
    $g_idGUIEdit = GUICtrlCreateEdit("", 5, 405, 990, 175)
    ; GUICtrlSetBkColor(-1, 0x000000)
    ; GUICtrlSetColor(-1, 0x00FF00)
    GUICtrlSetFont(-1,12, 400, -1, 'Courier New')
    GUICtrlCreateLabel("Below are some Browser events 'captured' from the above web page by AutoIt", 5, 385,990, 20)
    Local $idGUIExit = GUICtrlCreateButton(" Close and exit", 5, 580, 990, 15)
    GUISetState() ;Show GUI

    ; We prepare the Internet Explorer as our test subject
    Global $oIE = ObjCreate("Shell.Explorer.2")
    $hIE = GUICtrlCreateObj($oIE, 5, 5, 990, 380) ; <- insert $oIE in the AutoIt GUI

    ; Here we load an example Web page just to have something viewed in the browser
    $oIE.navigate('http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onmousemoveEX.htm')
    Sleep(1000) ; Give it some time to load the web page

    Do ; wait for document
        Sleep(250)
        $oDocument = $oIE.document
    Until IsObj($oDocument)

    ;   +  Scripting Object Interfaces
    ;   |  ---------------------------
    ;   |  https://msdn.microsoft.com/en-us/library/hh801967(v=vs.85).aspx
    ;   |
    ;   +-->   HTMLDocumentEvents2 interface (catch OnClick, OnMouseOver, .... etc
    ;          -----------------------------
    ;          https://msdn.microsoft.com/en-us/library/aa769764(v=vs.85).aspx
    ;
    Global $oEventObject = ObjEvent($oDocument, "IEEvent2_", "HTMLDocumentEvents2")

    If @error Then
        MsgBox($MB_OK, "AutoIt COM Test", _
                "ObjEvent: Can't use event interface 'HTMLDocumentEvents2'. Error code: " & Hex(@error, 8))
        Exit
    EndIf

    ; GUISwitch($hGUIMain) ; Switch back to our GUI in case IE stole the focus

    ; Waiting for user to close the GUI.
    Local $iMsg
    While 1
        $iMsg = GUIGetMsg()
        If $iMsg = $GUI_EVENT_CLOSE Or $iMsg = $idGUIExit Then ExitLoop
    WEnd

    $oEventObject.Stop ; Tell IE we don't want to receive events.
    $oEventObject = 0 ; Kill the Event Object
    $oIE = 0 ; Remove IE from memory (not really necessary).

    GUIDelete() ; Remove GUI
EndFunc   ;==>Example

; A few Internet Explorer Event Functions
Func IEEvent2_onClick()
    ConsolePrint("mouse click:")
EndFunc   ;==>IEEvent2_onClick

Func IEEvent2_onDblClick()
    ConsolePrint("mouse DoubleClick:")
EndFunc   ;==>IEEvent2_onDoubleClick

Func IEEvent2_onMouseMove($oEvent)
    ; according to what is written here:
    ; https://msdn.microsoft.com/en-us/library/ms536947(v=vs.85).aspx
    ; I should be able to get properties from the event using the 'event.property' syntax
    ; but how to refer to the 'event' obj <---- ???????
    ; ConsolePrint("mouse moved to:" & @TAB & "Xpos = " & $oEvent.clientX & @TAB & "Ypos = " & $oEvent.clientY ) ; <-- error
    ConsolePrint("mouse moved to: ???" & @TAB & "Xpos = " & "event.clientX" & @TAB & "Ypos = " & "event.clientY")
EndFunc   ;==>IEEvent2_onMouseMove

Func ConsolePrint($sMsg)
    Local Const $iMaxLines = 12 ; keep last 12 lines only
    $sMsg = @HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC & @TAB & $sMsg & @CRLF
    $sMsg = StringReplace(GUICtrlRead($g_idGUIEdit) & $sMsg, @CR, @CR)
    If @extended > $iMaxLines Then ; more than $iMaxLines
        $sMsg = StringMid($sMsg, StringInStr($sMsg, @CR, 0, -1 * $iMaxLines) + 2)
    EndIf
    GUICtrlSetData($g_idGUIEdit, $sMsg)
EndFunc   ;==>ConsolePrint

any help will be appreciated.
Thanks

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted
Posted (edited)

Thanks reverend @Danyfirex
I see, declaring event functions as Volatile those works :).

; We use a very simple GUI to show the results of our Events.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Global $g_idGUIEdit

Example()
Exit ; End of our Demo.

Func Example()
    Local $hGUIMain = GUICreate("Event Test", 1000, 600)
    $g_idGUIEdit = GUICtrlCreateEdit("", 5, 405, 990, 175)
    ; GUICtrlSetBkColor(-1, 0x000000)
    ; GUICtrlSetColor(-1, 0x00FF00)
    GUICtrlSetFont(-1, 9, 400, -1, 'Courier New')
    GUICtrlCreateLabel("Below are some Browser events 'captured' from the above web page by AutoIt", 5, 385, 990, 20)
    Local $idGUIExit = GUICtrlCreateButton(" Close and exit", 5, 580, 990, 15)
    GUISetState() ;Show GUI

    ; We prepare the Internet Explorer as our test subject
    Global $oIE = ObjCreate("Shell.Explorer.2")
    $hIE = GUICtrlCreateObj($oIE, 5, 5, 990, 380) ; <- insert $oIE in the AutoIt GUI

    ; Here we load an example Web page just to have something viewed in the browser
    $oIE.navigate('http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onmousemoveEX.htm')
    Sleep(1000) ; Give it some time to load the web page

    Do ; wait for document
        Sleep(250)
        $oDocument = $oIE.document
    Until IsObj($oDocument)

    ;   +  Scripting Object Interfaces
    ;   |  ---------------------------
    ;   |  https://msdn.microsoft.com/en-us/library/hh801967(v=vs.85).aspx
    ;   |
    ;   +-->   HTMLDocumentEvents2 interface (catch OnClick, OnMouseOver, .... etc
    ;          -----------------------------
    ;          https://msdn.microsoft.com/en-us/library/aa769764(v=vs.85).aspx
    ;
    Global $oEventObject = ObjEvent($oDocument, "IEEvent2_", "HTMLDocumentEvents2")

    If @error Then
        MsgBox($MB_OK, "AutoIt COM Test", _
                "ObjEvent: Can't use event interface 'HTMLDocumentEvents2'. Error code: " & Hex(@error, 8))
        Exit
    EndIf

    ; GUISwitch($hGUIMain) ; Switch back to our GUI in case IE stole the focus

    ; Waiting for user to close the GUI.
    Local $iMsg
    While 1
        $iMsg = GUIGetMsg()
        If $iMsg = $GUI_EVENT_CLOSE Or $iMsg = $idGUIExit Then ExitLoop
    WEnd

    $oEventObject.Stop ; Tell IE we don't want to receive events.
    $oEventObject = 0 ; Kill the Event Object
    $oIE = 0 ; Remove IE from memory (not really necessary).

    GUIDelete() ; Remove GUI
EndFunc   ;==>Example

; A few Internet Explorer Event Functions
; ( reference to the Event Obj interface: )
; ( https://msdn.microsoft.com/en-us/library/aa703876(v=vs.85).aspx )
;
Volatile Func IEEvent2_onClick($oEvent)
    ConsolePrint("mouse click: " & $oEvent.clientX & ',' & $oEvent.clientY & '  on ' & $oEvent.srcElement.NodeName)
EndFunc   ;==>IEEvent2_onClick

Volatile Func IEEvent2_onDblClick($oEvent)
    ConsolePrint("mouse DoubleClick: @" & $oEvent.clientX & ',' & $oEvent.clientY)
EndFunc   ;==>IEEvent2_onDblClick

Volatile Func IEEvent2_onMouseMove($oEvent)
    ConsolePrint("mouse moved to:" & @TAB & "Xpos = " & $oEvent.clientX & @TAB & "Ypos = " & $oEvent.clientY)
EndFunc   ;==>IEEvent2_onMouseMove

Func ConsolePrint($sMsg)
    Local Const $iMaxLines = 9 ; keep last 9 log lines only
    $sMsg = @HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC & @TAB & $sMsg & @CRLF
    $sMsg = StringReplace(GUICtrlRead($g_idGUIEdit) & $sMsg, @CR, @CR)
    If @extended > $iMaxLines Then ; more than $iMaxLines
        $sMsg = StringMid($sMsg, StringInStr($sMsg, @CR, 0, -1 * $iMaxLines) + 2)
    EndIf
    GUICtrlSetData($g_idGUIEdit, $sMsg)
EndFunc   ;==>ConsolePrint


p.s.
:huh2: volatile? :think:... yes volatile, naturally! ... :blink:

Edited by Chimp
added link for Event Obj interface

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted
  On 10/29/2016 at 11:39 PM, Chimp said:

:huh2: volatile? :think:... yes volatile, naturally! ... :blink:

Expand  

Just exactly what I said here:

;)

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 10/28/2016 at 11:57 AM, trancexx said:

I removed that from AutoIt few years back. The feature was consuming too many resources and have been slowing down execution.
On top of that, the feature is senseless. You either know what you want to capture, or don't capture at all. Third option is just gay.

Unfortunately I missed the example script from the help file.

Expand  

I was using this functionality for testing purposes. It was very convenient. That way i was looking on the events that were firing at the time i was clicking on a IE page and later on i was refining the code. How do you propose to do that now?

@PS

What does Volatile means? I cant use it - my AutoIT(v3.3.8.1) gives me compilation error "ERROR: syntax error".

Edited by Juvigy
PS
  • 1 year later...
Posted

Howdy,

  First of all...thank you so much for that script @Chimp (and @Danyfirex)...!!!   I just stumbled upon it and it is amazing...it will help me a great deal...

  I have already slightly modified it by adding the ability to display/read the .innertext of a 'clicked' element...now I just wonder is there a way to 'select' the text of an element that has been clicked (for example a <p> or <li> or <td> or whatever)....?  Just a basic 'highlight' selection of the clicked element would be cool.

  It would also be helpful to me to be able to click/drag the element text on the webpage...and read/save that particular .innertext that was highlighted by the user.  For example if the .innertext of a <p> element is "This is some text" and the user clicks/drags on the "This is some" I would like to be able to 'break' that out from the tag...possible...?

  I thought I saw some mention of something similar to that in MS documentation...but I cannot remember where it is or if that would accomplish this...any ideas/suggestions welcome.  Once again thanks for that great code example... !

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...