Leaderboard
Popular Content
Showing content with the highest reputation on 05/11/2019 in all areas
-
1 point
-
I need to ask this, what is the point of all this? What EXACTLY are you trying to show, prove, disprove, or report with all of this spaghetti coding?1 point
-
Alright! Hope you have a good time coding! Regards, Supra1 point
-
thanks for the correction , the path is correct and everything looks good however the program is still not starting , i will check the program and perhaps test the same script but on a diffrent program to make sure msi afterburner is not at fault for it not starting up. thanks a bunch for all your support guys il post if i find anything new but scrip looks good1 point
-
It is not about stupidity, merely taking the time to think it through...understand... and moreover TEST... which is called in general "learning". Jos1 point
-
Try to reread my question, think, search , test and then reply again.1 point
-
Auto decide which @IPAddress1-4 to take
argumentum reacted to LWC for a topic
TCPNameToIP(@ComputerName) actually matches @IPAddress1 (the emulated one), not @IPAddress2 (the actual internal one), so it doesn't change anything. _GetIP() is not relevant as I need the right internal address, not an external one. So I've ended up successfully using the following code, which finds the first adapter which has a gateway, as it seems like emulated ones don't have gateways. But I do wish @IPAddress1-4 would have just given priority to non emulated addresses over emulated ones. $internal_not_emulated_ip_address=_GetGateway()[0] Func _GetGateway() ; Based on: ; Rajesh V R ; v 1.0 01 June 2009 ; use the adapter name as seen in the network connections dialog... Const $wbemFlagReturnImmediately = 0x10 Const $wbemFlagForwardOnly = 0x20 Local $colNICs="", $NIC, $strQuery, $objWMIService $strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration" $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2") $colNICs = $objWMIService.ExecQuery($strQuery, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) Local $output[2] If IsObj($colNICs) Then For $NIC In $colNICs if isstring($NIC.DefaultIPGateway(0)) then $output[0] = $NIC.IPAddress(0) $output[1] = $NIC.DefaultIPGateway(0) ExitLoop endif Next Else Return SetError(-1, 0, "No WMI Objects Found for class: Win32_NetworkAdapterConfiguration") EndIf Return $output EndFunc1 point -
juniq, You acknowledged the warning I gave you about useless necro-posting - and yet here you are at it again. Take a week off to reconsider your behaviour - because another episode will see you removed from the community. M231 point
-
try this way... #include <IE.au3> HotKeySet("{ESC}", "_Close") _IEErrorHandlerRegister(_ErrFunc) $oIE = _IECreateEmbedded() $hGui = GUICreate("Test", 700, 500, -1, -1) GUICtrlCreateObj($oIE, 0, 0, 700, 500) _IENavigate($oIE, "about:blank") $sHTML = "" $sHTML &= "<html>" $sHTML &= "<head>" $sHTML &= "<title>Test</title>" $sHTML &= "</head>" $sHTML &= "<body>" $sHTML &= '<button type="button" id="btnMenu">=</button>' $sHTML &= '<button type="button" id="btnClose">X</button>' $sHTML &= "</body>" $sHTML &= "</html>" _IEDocWriteHTML($oIE, $sHTML) _IEAction($oIE, "refresh") GUISetState() ; ------------------------------------------------------------------------------- ; inject a reference to the javascript global object into the WebBrowser document ; this works for the BrowserControl, but it doesn't on the IE browser ; ; http://perfectionkills.com/unnecessarily-comprehensive-look-into-a-rather-insignificant-issue-of-global-objects-creation/#ecmascript_5_strict_mode $oIE.document.parentwindow.setTimeout("JSglobal = (1,eval)(""this"");", 0) Local $ohJS Do Sleep(1000) $ohJS = Execute('$oIE.document.parentwindow.JSglobal') Until IsObj($ohJS) ; getting references to javascript objects in this way will then work on ObjEvent $oButtonMenu = $ohJS.btnMenu ;_IEGetObjById($oIE, "btnMenu") $oButtonClose = $ohJS.btnClose ; _IEGetObjById($oIE, "btnClose") ; ------------------------------------------------------------------------------- $oEvent = ObjEvent($oButtonMenu, "_MY_EVENT_HANDLER_", "HTMLButtonElementEvents2") $oEvent2 = ObjEvent($oButtonClose, "_MY_EVENT_HANDLER_", "HTMLButtonElementEvents2") While (1) Sleep(20) WEnd Volatile Func _MY_EVENT_HANDLER_onclick($oEventObj) ; https://msdn.microsoft.com/en-us/library/aa703876(v=vs.85).aspx MsgBox(4096, "Yay!", "You clicked the button. But which one ? this ID --> " & $oEventObj.srcElement.id) EndFunc ;==>_MY_EVENT_HANDLER_onclick Func _Close() ; the end $oEvent.stop $oEvent2.stop $oEvent = 0 $oEvent2 = 0 $oIE = 0 ; Remove IE from memory GUIDelete($hGui) ; Remove GUI Exit EndFunc ;==>_Close Func _ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc p.s. For another example of use for the WebControl, have a look to this script also... (https://www.autoitscript.com/forum/topic/186422-who-is-who-a-little-dragdrop-game/)1 point
-
This is a little experiment that makes use of a "Browser Control" embedded in a GUI in order to be able to use AutoIt, HTML, JavaScript and CSS all together. This little toy will only work on systems with IE11. The purpose is to drag all the names of the scientists & drop on the right ones. (among scientists it has also infiltrated an intruder). I hope you find it entertaining. I've posted it here in the hope to have some suggestions on how to improve it all (I mean the interaction between Autoit Javascript html and css). Thanks ; this works on systems with IE11 ; ------------------------------- #include <GUIConstantsEx.au3> #include <array.au3> Global $oIE, $oDocument, $ohJS, $sDroping Global $iCorrect = 0, $iGoal = 11 Example() Exit Func Example() Local $aScientists[12][2] = _ [["Schrodinger", "Schrodinger"],["Planck", "Planck"],["Pauli", "Pauli"],["Einstein", "Einstein"], _ ["Chimp", "Chimp"],["Dirac", "Dirac"],["Heisenberg", "Heisenberg"],["Born", "Born"], _ ["De Broglie", "De_Broglie"],["Bohr", "Bohr"],["Sommerfeld", "Sommerfeld"],["", "empty"]] Local $oIE = ObjCreate("Shell.Explorer.2") ; Create a BrowserControl Local $hGUI = GUICreate("", 660, 600, 30, 30) GUICtrlCreateObj($oIE, 0, 0, 660, 600) ; Place BrowserControl on the GUI GUISetState() ;Show GUI $oIE.navigate('about:blank') ; file:///' & @ScriptDir & '\WhoIsWho.html') While Not String($oIE.readyState) = 'complete' ; wait for about:blank Sleep(100) WEnd ; this waits till the document is ready to be used (portion of code from IE.au3) While Not (String($oIE.readyState) = "complete" Or $oIE.readyState = 4) Sleep(100) WEnd While Not (String($oIE.document.readyState) = "complete" Or $oIE.document.readyState = 4) Sleep(100) WEnd $oIE.document.Write(_GetHTML()) ; inject lising directly to the HTML document: $oIE.document.close() ; close the write stream $oIE.document.execCommand("Refresh") While Not String($oIE.readyState) = 'complete' ; wait for readyState after a refresh Sleep(100) WEnd ; https://msdn.microsoft.com/en-us/library/52f50e9t(v=vs.94).aspx ; $ohJS is a reference to the javascript Global Obj ; ------------------------------------------------- $ohJS = $oIE.document.parentwindow.JSglobal $oDocument = $oIE.document Local $oTable1 = $ohJS.table1 Local $oTable2 = $ohJS.table2 _Randomize($aScientists, $oTable1) ; --- Setup events ------------ ; https://msdn.microsoft.com/en-us/library/hh801967(v=vs.85).aspx Local $aoEventObject[2] $aoEventObject[0] = ObjEvent($oTable1, "IEEvent_", "HTMLTableEvents2") $aoEventObject[1] = ObjEvent($oTable2, "IEEvent_", "HTMLTableEvents2") ; ----------------------------- ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch If $iCorrect = $iGoal Then _Goal() _Randomize($aScientists, $oTable1) $iCorrect = 0 EndIf WEnd ; the end For $i = 0 To UBound($aoEventObject) - 1 $aoEventObject[$i] .stop Next $aoEventObject = 0 ; Kill the Event Object $oIE = 0 ; Remove IE from memory (not really necessary). GUIDelete($hGUI) ; Remove GUI EndFunc ;==>Example ; --- event management zone --- ; following functions are fired by events occurred in the browser control Volatile Func IEEvent_onDragstart($oEvent) ; we save the ID of the dragged obj into the $sDroping variable ; for a later use in the drop function $sDroping = $oEvent.srcElement.ID EndFunc ;==>IEEvent_onDragstart Volatile Func IEEvent_onDragOver($oEvent) $ohJS.event.preventDefault() EndFunc ;==>IEEvent_onDragOver Volatile Func IEEvent_onDrop($oEvent) $ohJS.event.preventDefault() If $sDroping <> "" Then If $oDocument.getElementById($sDroping).innerText <> $oEvent.srcElement.innerText Then If $oEvent.srcElement.ClassName = $oDocument.getElementById($sDroping).ClassName Then $oEvent.srcElement.innerText = $oDocument.getElementById($sDroping).innerText $oDocument.getElementById($sDroping).innerText = "" $oDocument.getElementById($sDroping).draggable = False $oDocument.getElementById($sDroping).setAttribute("style") = "background-color: #80ff80;" $iCorrect += 1 Else For $i = 1 To 3 $oDocument.getElementById($sDroping).setAttribute("style") = "background-color: #ff0000;" Sleep(125) $oDocument.getElementById($sDroping).setAttribute("style") = "background-color: #ffffff;" Sleep(125) Next EndIf EndIf $sDroping = "" EndIf EndFunc ;==>IEEvent_onDrop Func _Randomize(ByRef $aScientists, ByRef $oTable) Local $iRows = ($oTable.rows.length) - 1 Local $iCols = ($oTable.rows.item(0).cells.length) - 1 Local $index _ArrayShuffle($aScientists) For $y = 0 To $iRows For $x = 0 To $iCols $index = ($y * ($iCols + 1)) + $x $oTable.rows.item($y).cells.item($x).innerText = $aScientists[$index][0] ; text $oTable.rows.item($y).cells.item($x).className = $aScientists[$index][1] ; class $oTable.rows.item($y).cells.item($x).draggable = $aScientists[$index][0] <> "" Next Next EndFunc ;==>_Randomize Func _Goal() Local $oTable1 = $ohJS.table1 ; names Local $oTable2 = $ohJS.table2 ; photos Local $iRows = ($oTable1.rows.length) Sleep(250) Local $iCols = 6 ; ($oTable1.rows.item(0).cells.length) Local $aIndex[$iRows * $iCols], $sTemp For $i = 0 To UBound($aIndex) - 1 $aIndex[$i] = $i ; + 1 Next _ArrayShuffle($aIndex) For $i = 0 To UBound($aIndex) - 1 $oTable2.rows.item(Int($aIndex[$i] / $iCols)).cells.item(Mod($aIndex[$i], $iCols)).innerText = "" $oTemp0 = $oTable2.rows $oTemp1 = $oTemp0.item(Int($aIndex[$i] / $iCols)).cells $oTemp2 = $oTemp1.item(Mod($aIndex[$i], $iCols)).getAttribute("style") $oTable2.rows.item(Int($aIndex[$i] / $iCols)).cells.item(Mod($aIndex[$i], $iCols)).setAttribute("style") = "background-color: " & _rndColor() Sleep(100); MsgBox(0,"Debug",$sTemp) $oTable2.rows.item(Int($aIndex[$i] / $iCols)).cells.item(Mod($aIndex[$i], $iCols)).setAttribute("style") = $oTemp2 Next For $x = 1 To 2 For $i = 0 To UBound($aIndex) - 1 $oTable1.rows.item(Int($aIndex[$i] / $iCols)).cells.item(Mod($aIndex[$i], $iCols)).setAttribute("style") = "background-color: " & _rndColor() Sleep(100) $oTable1.rows.item(Int($aIndex[$i] / $iCols)).cells.item(Mod($aIndex[$i], $iCols)).setAttribute("style") = "background-color: #ffffff;" Next Next EndFunc ;==>_Goal Func _rndColor() Return String("#" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & ";") EndFunc ;==>_rndColor Func _GetHTML() Local $sHTML = _ "<!DOCTYPE HTML>" & @CRLF & _ "<html>" & @CRLF & _ "<head>" & @CRLF & _ "<meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />" & @CRLF & _ " <script type=""text/javascript"">" & @CRLF & _ " var JSglobal = (1,eval)(""this"");" & @CRLF & _ " </script>" & @CRLF & _ "</head>" & @CRLF & _ "<body>" & @CRLF & _ "<h2>Who is who?</h2>" & @CRLF & _ "<p>Drag&Drop names on the right scientist</p>" & @CRLF & _ "<img src=""https://i.imgur.com/STWql7w.jpg""" & @CRLF & _ "height=""394"" width=""640""" & @CRLF & _ "style=""position: absolute; left: 10px; top: 100px;"">" & @CRLF & _ "" & @CRLF & _ "<style>" & @CRLF & _ ".target td {width: 100px; height: 160px; text-align: center; color: white; font-weight: bold; vertical-align: bottom; border: 0px solid grey;}" & @CRLF & _ ".source td {width: 100px; height: 30px; text-align: center; border: 1px solid red;}" & @CRLF & _ "</style>" & @CRLF & _ "" & @CRLF & _ "<table class=""target"" style=""position: absolute; left: 25px; top: 100px;"" id=""table2"">" & @CRLF & _ " <tr><td class=""Schrodinger""></td><td class=""Planck""></td><td class=""Pauli""></td><td class=""Einstein""></td><td class=""Chimp""></td><td class=""Dirac""></td></tr>" & @CRLF & _ " <tr><td class=""Heisenberg""></td><td class=""Born""></td><td class=""De_Broglie""></td><td class=""Bohr""></td><td class=""Sommerfeld""></td><td class=""empty""></td></tr>" & @CRLF & _ "</table>" & @CRLF & _ "" & @CRLF & _ "<table class=""source"" style=""position: absolute; left: 10px; top: 504px;"" id=""table1"">" & @CRLF & _ " <tr><td ID=""td1""></td><td ID=""td2""></td><td ID=""td3""></td><td ID=""td4"" ></td><td ID=""td5"" ></td><td ID=""td6"" ></td></tr>" & @CRLF & _ " <tr><td ID=""td7""></td><td ID=""td8""></td><td ID=""td9""></td><td ID=""td10""></td><td ID=""td11""></td><td ID=""td12""></td></tr>" & @CRLF & _ "</table>" & @CRLF & _ "</body>" & @CRLF & _ "</html>" Return $sHTML EndFunc ;==>_GetHTML1 point
-
Meh, I forgot that you can make event functions execute synchronously. LOL and I wrote the code for that. Yes, you can get id or object that fired the event from within event function: Global $oIE = ObjCreate("InternetExplorer.Application") Local $oEventBrowser = ObjEvent($oIE, "Browser_", "DWebBrowserEvents2") Local $oEventLink1, $oEventButton2 ; to collect event objects to $oIE.navigate("about:blank") ;----------------------------------------------- While Sleep(100) WEnd ; THE END ;----------------------------------------------- Func Customize($oBrowser, ByRef $oEventLink1, ByRef $oEventButton2) Local $sHtml = '<body> <a id="idLink" href="#" title="Link" >Click me</a> <br><br> <button id="idButton" title="Button" >Click me</button> </body>' Local $oDoc = $oBrowser.document $oDoc.write($sHtml) $oBrowser.visible = True Local $oLink1 = $oDoc.getElementById("idLink") Local $oButton2 = $oDoc.getElementById("idButton") ; Event objects $oEventLink1 = ObjEvent($oLink1, "Event_", "HTMLAnchorEvents2") $oEventButton2 = ObjEvent($oButton2, "Event_", "HTMLButtonElementEvents2") EndFunc ;Events for browser Func Browser_OnQuit() Exit EndFunc Func Browser_DocumentComplete($oDisp, $sUrl) Customize($oDisp, $oEventLink1, $oEventButton2) EndFunc ; Events volatile Func Event_onmouseover($oEvtObj) If IsObj($oEvtObj) Then ConsoleWrite("id = " & $oEvtObj.srcElement.id & " fired onmouseover" & @CRLF) Switch $oEvtObj.srcElement Case $oIE.document.getElementById("idLink") $oEvtObj.srcElement.innerhtml = "Hovering Anchor" Case $oIE.document.getElementById("idButton") $oEvtObj.srcElement.innerhtml = "Hovering Button (click to Exit)" EndSwitch EndIf EndFunc volatile Func Event_onmouseout($oEvtObj) If IsObj($oEvtObj) Then ConsoleWrite("id = " & $oEvtObj.srcElement.id & " fired onmouseout" & @CRLF) Switch $oEvtObj.srcElement ; check Case $oIE.document.getElementById("idLink") $oEvtObj.srcElement.innerhtml = "Not Hovering Anchor" Case $oIE.document.getElementById("idButton") $oEvtObj.srcElement.innerhtml = "Not Hovering Button (click to Exit)" EndSwitch EndIf EndFunc volatile Func Event_onclick($oEvtObj) If IsObj($oEvtObj) Then ConsoleWrite("id = " & $oEvtObj.srcElement.id & " fired onclick" & @CRLF) If $oEvtObj.srcElement = $oIE.document.getElementById("idButton") Then $oIE.Quit() Exit EndIf EndIf EndFunc Then It has to be HTMLAnchorEvents2, HTMLButtonElementEvents2, etc... You can compare id-s or objects directly to get the one that fired (i'm checking objects in that example).1 point
-
It's not about whether it's complicated or not, it's about how it should be done. That other thing is how it should be done: Local $sHtml = '<body> <a id="idLink" href="#" title="Link" >Click me</a> <br><br> <button id="idButton" title="Button" >Click me</button> </body>' Local $oIE = ObjCreate("InternetExplorer.Application") $oIE.navigate("about:blank") Sleep(200) ; lame $oIE.document.write($sHtml) $oIE.visible = True Local $oDoc = $oIE.document ConsoleWrite(@error & @CRLF) Local $oLink1 = $oIE.document.getElementById("idLink") Local $oButton2 = $oIE.document.getElementById("idButton") ; Event objects Local $oEventBrowser = ObjEvent($oIE, "Browser_", "DWebBrowserEvents2") Local $oEventLink1 = ObjEvent($oLink1, "Link1_") Local $oEventButton2 = ObjEvent($oButton2, "Button2_") ;----------------------------------------------- While Sleep(100) WEnd ; THE END ;----------------------------------------------- ;Events for browser Func Browser_OnQuit() Exit EndFunc ; Events for link Func Link1_onclick($oEvtObj) $oIE.document.getElementById("idLink").innerhtml = "You clicked me" EndFunc Func Link1_onmouseover($oEvtObj) $oIE.document.getElementById("idLink").innerhtml = "Hovering" EndFunc Func Link1_onmouseout($oEvtObj) $oIE.document.getElementById("idLink").innerhtml = "Not Hovering" EndFunc ; Events for button Func Button2_onmouseover($oEvtObj) $oIE.document.getElementById("idButton").innerhtml = "Hovering Button (click to Exit)" EndFunc Func Button2_onmouseout($oEvtObj) $oIE.document.getElementById("idButton").innerhtml = "Not Hovering Button (click to Exit)" EndFunc Func Button2_onclick($oEvtObj) $oIE.Quit() Exit EndFunc Or even better: Global $oIE = ObjCreate("InternetExplorer.Application") Local $oEventBrowser = ObjEvent($oIE, "Browser_", "DWebBrowserEvents2") Local $oEventLink1, $oEventButton2 ; to collect event objects to $oIE.navigate("about:blank") ;----------------------------------------------- While Sleep(100) WEnd ; THE END ;----------------------------------------------- Func Customize($oBrowser, ByRef $oEventLink1, ByRef $oEventButton2) Local $sHtml = '<body> <a id="idLink" href="#" title="Link" >Click me</a> <br><br> <button id="idButton" title="Button" >Click me</button> </body>' Local $oDoc = $oBrowser.document $oDoc.write($sHtml) $oBrowser.visible = True Local $oLink1 = $oDoc.getElementById("idLink") Local $oButton2 = $oDoc.getElementById("idButton") ; Event objects $oEventLink1 = ObjEvent($oLink1, "Link1_") $oEventButton2 = ObjEvent($oButton2, "Button2_") EndFunc ;Events for browser Func Browser_OnQuit() Exit EndFunc Func Browser_DocumentComplete($oDisp, $sUrl) Customize($oDisp, $oEventLink1, $oEventButton2) EndFunc ; Events for link Func Link1_onclick($oEvtObj) $oIE.document.getElementById("idLink").innerhtml = "You clicked me" EndFunc Func Link1_onmouseover($oEvtObj) $oIE.document.getElementById("idLink").innerhtml = "Hovering" EndFunc Func Link1_onmouseout($oEvtObj) $oIE.document.getElementById("idLink").innerhtml = "Not Hovering" EndFunc ; Events for button Func Button2_onmouseover($oEvtObj) $oIE.document.getElementById("idButton").innerhtml = "Hovering Button (click to Exit)" EndFunc Func Button2_onmouseout($oEvtObj) $oIE.document.getElementById("idButton").innerhtml = "Not Hovering Button (click to Exit)" EndFunc Func Button2_onclick($oEvtObj) $oIE.Quit() Exit EndFunc1 point
-
howto get current directory a script was started from?
atetester132 reacted to hannes08 for a topic
Hi rudi, try this: MsgBox(0,"test",@ScriptDir & @CRLF & @WorkingDir) I think the second macro (@WorkingDir) will lead you to the right way! Regards, Hannes1 point -
Click relative to window
AndrewSchultz reacted to Aassdd for a topic
First way: Opt("WinTitleMatchMode", 2) $pos = WinGetPos("Notepad") $x = 300 $y = 30 WinWaitActive("Notepad") MouseClick("left", $pos[0] + $x, $pos[1] + $y) Second way: ControlCick butnot exactly what you looking for.1 point