Leaderboard
Popular Content
Showing content with the highest reputation on 10/11/2022 in all areas
-
Detecting Windows API Sets on a Device - (Moved)
argumentum reacted to AutoXenon for a topic
Local $apiSet = InputBox("Enter API Set","Enter name of API set to be queried","ext-ms-win-ntuser-rawinput-l1-1-0") If $apiSet Then Local $aCall = DllCall("api-ms-win-core-apiquery-l2-1-0.dll", "BOOL", "IsApiSetImplemented", "STR", $apiSet) MsgBox(0,$apiSet,$aCall[0]) EndIf From here: https://learn.microsoft.com/en-us/windows/win32/apiindex/windows-apisets What do you guys think of adding this to autoit's Includes udfs? On one hand, this is only for Win10 and later, but on the other hand it's pretty significant for not taking for granted the assumption that the full set of Windows api features are available on all devices.1 point -
Hi, there appears to be a mistake. The code pasted here _is_ the demonstration example for how to detect API sets. The questions underneath are incidental "food for thoughts" but is not the main point of the thread.1 point
-
Hello @robertocm I don't know what the final purpose of that script is, however I have made some changes to be able to receive events from the 'firstname' element as it is contained in a form (see lines 81 to 88) I also changed the variable name "firstname" to "firstname2" in the javascript list (see lines 188 and 201) as it appears that if it has the same name as the ID, the AutoIt ObjEvent command fails. p.s. I managed to get it to work by trial and error, but I don't know exactly why it works that way .... (what ugly beasts these events are ....) #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') ;>>>> ;These lines from: Chimp, Jan 2017 (edited) ;Who is Who ? (a little drag&drop game) ;https://www.autoitscript.com/forum/topic/186422-who-is-who-a-little-dragdrop-game/ ;Global $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 $oDocument = $oIE.document ;>>>> ;~ 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 ; ============================================================== ; Local $oForm = _IEFormGetCollection($oIE, 0) ; <-- using ie.au3 Local $oForm = $oIE.document.forms.item(0) ; Get a reference to the (first) Form object Local $MyRef = $oIE.document.getElementById('firstname') ; get element with id 'firstname' Local $hMyObj = _WebBrowser_JS_ElementGetRef($oForm, $MyRef) ; get reference of $MyRef from $oForm ; https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa753143(v=vs.85) Global $oEventObjectInput = ObjEvent($hMyObj, "IEEvent_Input_", "HTMLInputTextElementEvents2") Local $error = @error MsgBox(0, 'Debug; ObjEvent', VarGetType($oEventObjectInput)) ; OK if it is 'Object' If $error Then MsgBox($MB_OK, "AutoIt COM Test " & @ScriptLineNumber, _ "ObjEvent: Can't use event interface 'HTMLInputTextElementEvents2'. 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 & ' id: ' & $oEvent.srcElement.id) If $oEvent.srcElement.NodeName = "INPUT" Then If $oEvent.srcElement.type = "radio" Or $oEvent.srcElement.type = "checkbox" Then If $oEvent.srcElement.checked = True Then ConsolePrint("name: " & $oEvent.srcElement.name & " id " & $oEvent.srcElement.id & " True") Else ConsolePrint("name: " & $oEvent.srcElement.name & " id " & $oEvent.srcElement.id & " False") EndIf EndIf EndIf 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 ; =================================== Volatile Func IEEvent_Input_onkeydown($oEvent) ; onChange($oEvent) ConsolePrint("KeyCode: " & $oEvent.keyCode) EndFunc ;==>IEEvent_Input_onkeydown Volatile Func IEEvent_Input_onkeypress($oEvent) ; Fires when you exit from the input and ONLY IF YOU HAVE CHANGED IT'S CONTENT ; ---- ------------------------------------- ConsolePrint('Input content in "First name" field has changed') EndFunc ;==>IEEvent_Input_onkeypress ; =================================== 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 Func _GetHTML() ;form html code from: Marc Clifton, 16 Feb 2013, https://www.codeproject.com/Articles/547451/WebBrowser-Element-Events-and-Values ;JavaScript from: Marijn Haverbeke (2011), Eloquent JavaScript: a modern introduction to programming. No Starch Press, Inc. Local $sHTML = _ "<!DOCTYPE HTML>" & @CRLF & _ "<html>" & @CRLF & _ "<head>" & @CRLF & _ "<meta http-equiv='X-UA-Compatible' content='IE=edge' />" & @CRLF & _ "<title>Test</title>" & @CRLF & _ "</head>" & @CRLF & _ "<body>" & @CRLF & _ "<form>First name: <input id='firstname' type='text' name='firstname'/>" & @CRLF & _ "<br>" & @CRLF & _ "Last name: <input id='lastname' type='text' name='lastname'/>" & @CRLF & _ "<br>" & @CRLF & _ "Password: <input id='password' type='password' name='pwd'/>" & @CRLF & _ "<br>" & @CRLF & _ "<input type='radio' id='male' name='sex' value='male'/>Male" & @CRLF & _ "<br>" & @CRLF & _ "<input type='radio' id='female' name='sex' value='female'/>Female" & @CRLF & _ "<br>" & @CRLF & _ "<input type='checkbox' id='bike' name='vehicle' value='Bike'/>I have a bike" & @CRLF & _ "<br>" & @CRLF & _ "<input type='checkbox' id='car' name='vehicle' value='Car'/>I have a car" & @CRLF & _ "</form>" & @CRLF & _ "" & @CRLF & _ "<script type='text/javascript'>" & @CRLF & _ "var firstname2 = document.getElementById('firstname');" & @CRLF & _ ; <- changed firstname to firstname2 "var lastname = document.getElementById('lastname');" & @CRLF & _ "var password = document.getElementById('password');" & @CRLF & _ "var male = document.getElementById('male');" & @CRLF & _ "var female = document.getElementById('female');" & @CRLF & _ "var bike = document.getElementById('bike');" & @CRLF & _ "var car = document.getElementById('car');" & @CRLF & _ "" & @CRLF & _ "//Marijn Haverbeke (2011), Eloquent JavaScript: a modern introduction to programming. No Starch Press, Inc." & @CRLF & _ "var output = dom('DIV', {id: 'printOutput'}, dom('H3', null, 'Print output:'));" & @CRLF & _ "window.onload = document.body.appendChild(output);" & @CRLF & _ "// print('Hello');" & @CRLF & _ "" & @CRLF & _ "registerEventHandler(firstname2, 'change', function(event) {" & @CRLF & _ ; <- changed firstname to firstname2 "event = event || window.event;" & @CRLF & _ "print(event.srcElement.value);" & @CRLF & _ "});" & @CRLF & _ "" & @CRLF & _ "registerEventHandler(lastname, 'change', function(event) {" & @CRLF & _ "event = event || window.event;" & @CRLF & _ "print(event.srcElement.value);" & @CRLF & _ "});" & @CRLF & _ "" & @CRLF & _ "registerEventHandler(password, 'change', function(event) {" & @CRLF & _ "event = event || window.event;" & @CRLF & _ "print(event.srcElement.value);" & @CRLF & _ "});" & @CRLF & _ "" & @CRLF & _ "registerEventHandler(male, 'click', function(event) {" & @CRLF & _ "event = event || window.event;" & @CRLF & _ " if (event.srcElement.value = true) {" & @CRLF & _ " //ok" & @CRLF & _ " print(event.srcElement.outerHTML + ' Coordinates: ' + event.clientX + ' , ' + event.clientY);" & @CRLF & _ " //Not working (tested with Internet Explorer 7)" & @CRLF & _ " //print(event.srcElement.GetAttribute('name'));" & @CRLF & _ " }" & @CRLF & _ "});" & @CRLF & _ "" & @CRLF & _ "registerEventHandler(female, 'click', function(event) {" & @CRLF & _ "event = event || window.event;" & @CRLF & _ " if (event.srcElement.value = true) {" & @CRLF & _ " print(event.srcElement.outerHTML + ' Coordinates: ' + event.clientX + ' , ' + event.clientY);" & @CRLF & _ " }" & @CRLF & _ "});" & @CRLF & _ "" & @CRLF & _ "//Returning always true ?" & @CRLF & _ "registerEventHandler(bike, 'click', function(event) {" & @CRLF & _ "event = event || window.event;" & @CRLF & _ " if (event.srcElement.value = true) {" & @CRLF & _ " print(event.srcElement.value + ' Coordinates: ' + event.clientX + ' , ' + event.clientY);" & @CRLF & _ " }" & @CRLF & _ "});" & @CRLF & _ "" & @CRLF & _ "//Returning always true ?" & @CRLF & _ "registerEventHandler(car, 'click', function(event) {" & @CRLF & _ "event = event || window.event;" & @CRLF & _ " if (event.srcElement.value = true) {" & @CRLF & _ " print(event.srcElement.value + ' Coordinates: ' + event.clientX + ' , ' + event.clientY);" & @CRLF & _ " //Not working (tested with Internet Explorer 7)" & @CRLF & _ " //print(car.GetAttribute('checked'));" & @CRLF & _ " }" & @CRLF & _ "});" & @CRLF & _ "" & @CRLF & _ "function registerEventHandler(node, event, handler) {" & @CRLF & _ "if (typeof node.addEventListener == 'function')" & @CRLF & _ "node.addEventListener(event, handler, false);" & @CRLF & _ "else" & @CRLF & _ "node.attachEvent('on' + event, handler);" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "function print() {" & @CRLF & _ "var result = [];" & @CRLF & _ "forEach(arguments, function(arg){result.push(String(arg));});" & @CRLF & _ "output.appendChild(dom('PRE', null, result.join('')));" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "function dom(name, attributes, children) {" & @CRLF & _ "var node = document.createElement(name);" & @CRLF & _ "if (attributes) {" & @CRLF & _ "forEachIn(attributes, function(name, value) {" & @CRLF & _ "node.setAttribute(name, value);" & @CRLF & _ "});" & @CRLF & _ "}" & @CRLF & _ "for (var i = 2; i < arguments.length; i++) {" & @CRLF & _ "var child = arguments[i];" & @CRLF & _ "if (typeof child == 'string')" & @CRLF & _ "child = document.createTextNode(child);" & @CRLF & _ "node.appendChild(child);" & @CRLF & _ "}" & @CRLF & _ "return node;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "function forEachIn(object, action) {" & @CRLF & _ "for (var property in object) {" & @CRLF & _ "if (object.hasOwnProperty(property))" & @CRLF & _ "action(property, object[property]);" & @CRLF & _ "}" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "function forEach(array, action) {" & @CRLF & _ "for (var i = 0; i < array.length; i++)" & @CRLF & _ "action(array[i]);" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "</script>" & @CRLF & _ "</body>" & @CRLF & _ "</html>" Return $sHTML EndFunc ;==>_GetHTML ; see here: https://www.autoitscript.com/forum/topic/200338-browsercontrol-companion Func _WebBrowser_JS_ElementGetRef(ByRef $oIE_Server, $oElement) Local $oWindow = $oIE_Server ; $oIE_Server.document.parentwindow ; .JSglobal Local $oElementByIdReference If $oElement.Id = '' Then $oElement.setAttribute('Id', 'DummyId') ; we need an ID (a temporary ID) $oElementByIdReference = Execute('$oWindow.' & $oElement.getAttribute('Id')) ; get element's reference by Id $oElement.setAttribute('Id', '') ; remove the temporary ID (we leave things as we found them) Else $oElementByIdReference = Execute('$oWindow.' & $oElement.getAttribute('Id')) EndIf Return $oElementByIdReference EndFunc ;==>_WebBrowser_JS_ElementGetRef1 point
-
1 point
-
Monitoring folders and files - (Moved)
SkysLastChance reacted to orbs for a topic
no matter how you look at it, ReadDirectoryChangesW supports a single root path per thread - meaning, it can monitor only a single folder and its subfolders per thread. since AutoIt is not multithreaded, that limitation becomes process-dependent, rather than thread-dependent - meaning, one process can monitor only a single folder and its subfolders. the help file example for _WinAPI_ReadDirectoryChanges() is a perfectly workable script for a single folder, so if you rely on AutoIt alone, you need to run that script multiple times for multiple folders. a workaround is of course as suggested above, using an external DLL.1 point