Leaderboard
Popular Content
Showing content with the highest reputation on 07/16/2021 in Posts
-
Using an Object as Element in a Const Array In this post, an object is used as an element in a constant array. Still, it's possible to change an object property. How is that possible? Object variables access the object itself through a reference (pointer). A simple object variable can be created with the Dictionary object. Dictionary ObjectExamples\Example0.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=Y Opt( "MustDeclareVars", 1 ) Example() Func Example() Local $oDict1 = ObjCreate( "Scripting.Dictionary" ) ; Object reference counter = 1 Local $oDict2 = $oDict1 ; Object reference counter = 2 $oDict1.Item( "$vVar" ) = 123 $oDict1 = 0 ; Object reference counter = 1 ConsoleWrite( "$oDict2.Item( ""$vVar"" ) = " & $oDict2.Item( "$vVar" ) & @CRLF ) $oDict2 = 0 ; Object reference counter = 0 that deletes the object EndFunc #cs $oDict2.Item( "$vVar" ) = 123 #ce The variables $oDict1 and $oDict2 both refer to the same object. The Item property can be set with $oDict1 and read with $oDict2 and vice versa. Examples\Example1.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=Y Opt( "MustDeclareVars", 1 ) #include "..\Includes\InspectVariable.au3" Example() Func Example() Local $oDict1 = ObjCreate( "Scripting.Dictionary" ), $oDict2 = $oDict1 ConsoleWrite( "$oDict1" & @CRLF ) ConsoleWrite( "Type = " & VarGetType( $oDict1 ) & @CRLF ) AccessVariables01( InspectVariableMtd, $oDict1 ) ConsoleWrite( @CRLF ) ConsoleWrite( "$oDict2" & @CRLF ) ConsoleWrite( "Type = " & VarGetType( $oDict2 ) & @CRLF ) AccessVariables01( InspectVariableMtd, $oDict2 ) ConsoleWrite( @CRLF ) ConsoleWrite( "Ptr( $oDict1 ) = " & Ptr( $oDict1 ) & @CRLF ) EndFunc #cs $oDict1 Type = Object ptr = 0x00000000005CB110 ($pVariant) vt = 0x0009 (VT_DISPATCH, pointer to object) data = 0x00000000005B02B0 $oDict2 Type = Object ptr = 0x00000000005CB150 ($pVariant) vt = 0x0009 (VT_DISPATCH, pointer to object) data = 0x00000000005B02B0 Ptr( $oDict1 ) = 0x00000000005B02B0 #ce The InspectVariable.au3 UDF from Accessing AutoIt Variables is used to examine $oDict1 and $oDict2. Today we know that AutoIt variables are internally stored in variant structures. For object variables, the variant type is VT_DISPATCH, and the data field contains a pointer (reference) to the object. Note that this pointer has the same value for both object variables. And that it's the same pointer as returned by Ptr( $oDict1 ). The Item property of the Dictionary object is also a variant that can store all AutoIt data types. DllStruct TypeExamples\Example2.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=Y Opt( "MustDeclareVars", 1 ) Example() Func Example() Local $tagStruct = "struct;int var1;byte var2;uint var3;char var4[128];endstruct" Local $tStruct = DllStructCreate( $tagStruct ) DllStructSetData( $tStruct, "var1", -100 ) DllStructSetData( $tStruct, "var2", 255 ) DllStructSetData( $tStruct, "var3", 300 ) DllStructSetData( $tStruct, "var4", "Hello" ) Local $oDict1 = ObjCreate( "Scripting.Dictionary" ) Local $oDict2 = $oDict1 $oDict1.Item( "$tStruct" ) = $tStruct ConsoleWrite( "DllStructGetData( $oDict2.Item( ""$tStruct"" ), ""var3"" ) = " & DllStructGetData( $oDict2.Item( "$tStruct" ), "var3" ) & @CRLF ) EndFunc #cs DllStructGetData( $oDict2.Item( "$tStruct" ), "var3" ) = 300 #ce Array TypeAutoIt arrays are internally stored as safearrays of variants. Ie. the array itself is a safearray and the array elements are variant structures. Examples\Example3.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=Y Opt( "MustDeclareVars", 1 ) Example() Func Example() Local $oDict1 = ObjCreate( "Scripting.Dictionary" ) Local $oDict2 = $oDict1 Local $aArray[5] = [ 0, 1, 222, 3, 4 ] $oDict1.Item( "$aArray" ) = $aArray ConsoleWrite( "$oDict2.Item( ""$aArray"" )[2] = " & $oDict2.Item( "$aArray" )[2] & @CRLF ) ; $oDict1.Item( "$aArray" )[3] = 333 ; Error: Statement cannot be just an expression Local $aMyArray = $oDict1.Item( "$aArray" ) $aMyArray[3] = 333 $oDict1.Item( "$aArray" ) = $aMyArray ConsoleWrite( "$oDict2.Item( ""$aArray"" )[3] = " & $oDict2.Item( "$aArray" )[3] & @CRLF ) EndFunc #cs $oDict2.Item( "$aArray" )[2] = 222 $oDict2.Item( "$aArray" )[3] = 333 #ce Const ArrayA consequence of an object variable having access to the object itself through a reference makes it possible to store an object variable in a constant array (or constant variable) and still be able to change an object property. Since a change of an object property doesn't change the array element (or variable) that refers to the object, the property change doesn't conflict with a constant array (or variable). Examples\Example4.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=Y Opt( "MustDeclareVars", 1 ) Example() Func Example() Local $oDict = ObjCreate( "Scripting.Dictionary" ) $oDict.Item( "Int" ) = 1 $oDict.Item( "Flt" ) = 1.1 $oDict.Item( "Str" ) = "One" ;Local $aArray[1] = [ $oDict ] Local Const $aArray[1] = [ $oDict ] ; Local Const $oDict = 0 ConsoleWrite( "$aArray[0].Item( ""Int"" ) = " & $aArray[0].Item( "Int" ) & @CRLF ) ConsoleWrite( "$aArray[0].Item( ""Flt"" ) = " & $aArray[0].Item( "Flt" ) & @CRLF ) ConsoleWrite( "$aArray[0].Item( ""Str"" ) = " & $aArray[0].Item( "Str" ) & @CRLF & @CRLF ) #cs ; Direct modification of the $aArray values in this way doesn't work ; But it does work if you remove "Const" in the declaration of $aArray $aArray[0].Item( "Int" ) = 2 ; Error: $aArray previously declared as a 'Const' $aArray[0].Item( "Flt" ) = 2.2 ; Error: $aArray previously declared as a 'Const' $aArray[0].Item( "Str" ) = "Two" ; Error: $aArray previously declared as a 'Const' ConsoleWrite( "$aArray[0].Item( ""Int"" ) = " & $aArray[0].Item( "Int" ) & @CRLF ) ConsoleWrite( "$aArray[0].Item( ""Flt"" ) = " & $aArray[0].Item( "Flt" ) & @CRLF ) ConsoleWrite( "$aArray[0].Item( ""Str"" ) = " & $aArray[0].Item( "Str" ) & @CRLF & @CRLF ) #ce ;#cs ; Indirect modification of the $aArray values in this way does work Local $oMyDict = $aArray[0] $oMyDict.Item( "Int" ) = 2 $oMyDict.Item( "Flt" ) = 2.2 $oMyDict.Item( "Str" ) = "Two" $oMyDict = 0 ConsoleWrite( "$aArray[0].Item( ""Int"" ) = " & $aArray[0].Item( "Int" ) & @CRLF ) ConsoleWrite( "$aArray[0].Item( ""Flt"" ) = " & $aArray[0].Item( "Flt" ) & @CRLF ) ConsoleWrite( "$aArray[0].Item( ""Str"" ) = " & $aArray[0].Item( "Str" ) & @CRLF & @CRLF ) ;#ce EndFunc #cs $aArray[0].Item( "Int" ) = 1 $aArray[0].Item( "Flt" ) = 1.1 $aArray[0].Item( "Str" ) = One $aArray[0].Item( "Int" ) = 2 $aArray[0].Item( "Flt" ) = 2.2 $aArray[0].Item( "Str" ) = Two #ce This example is similar to the example in the link at top of post. 7z-fileThe 7z-file contains source code for UDFs and examples. You need AutoIt 3.3.12 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. Misc.7z3 points
-
Can you fix the HotKeySet and @HotKeyPressed
FrancescoDiMuro and one other reacted to ajag for a topic
I can not see any bug here... HotKeySet("&","CaptureAlert") works fine here on my german keyboard when pressing "SHIFT" and "6" at the same time HotKeySet("{}}","CaptureAlert") This is not a valid Key! What key do you want to be the HotKey here?2 points -
Can you fix the HotKeySet and @HotKeyPressed
JockoDundee reacted to jchd for a topic
Bunch of arrows!1 point -
@MoonscarletYou can solve this using the pageLoadStrategy setting, which is part of the Capabilities you pass to _WD_CreateSession. Searching the forum on the term "pageLoadStrategy" should yield multiple examples. P.S. As @Jos pointed out, this type of inquiry should be posted in the support thread over in the GH&S section (link in my sig) 😉1 point
-
Do you really think that our huge development team is just waiting to create a patch for you in the shortest possible time?</sarcasm> Back to real life: First you have to proof that it is a real bug Then you have to create a Trac ticket Then one of the developer has to accept the ticket as a bug Then one of the developer has to write a patch Then you have to wait for the release of the next beta version of AutoIt That's called professional software development. But I think this is nothing new for you, since you develop software yourself. So could you please start with step 1 ... BTW: We (developers, forum members ...) are just volunteers spending their rare spare time to develop and support AutoIt. So please be patient1 point
-
Advice for Getting Started with Android Development
Pumpkin_30 reacted to Earthshine for a topic
https://visualstudio.microsoft.com/xamarin/ i am telling you-- you CAN run VS and Xarmin on macos. so how bad do you want to do this? everything else isn't going to measure up to what you can do with this.1 point -
There is no function to search for an image. However there is _cveMatchTemplate that can be used for this purpose. For screen search, you can load the screen as a matrix, and from there use any opencv functions. Here is how to load a screen capture as a matrix #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WindowsConstants.au3> #include <WinAPI.au3> #include "emgucv-autoit-bindings\cve_extra.au3" Local $tDesktopScreenRect = _WinAPI_GetDesktopScreenRect() ConsoleWrite("$tDesktopScreenRect.left: " & $tDesktopScreenRect.left & @CRLF) ConsoleWrite("$tDesktopScreenRect.top: " & $tDesktopScreenRect.top & @CRLF) ConsoleWrite("$tDesktopScreenRect.right: " & $tDesktopScreenRect.right & @CRLF) ConsoleWrite("$tDesktopScreenRect.bottom: " & $tDesktopScreenRect.bottom & @CRLF) ConsoleWrite(@CRLF) Local $iLeft = $tDesktopScreenRect.left Local $iTop = $tDesktopScreenRect.top Local $biWidth = $tDesktopScreenRect.right - $tDesktopScreenRect.left Local $biHeight = $tDesktopScreenRect.bottom - $tDesktopScreenRect.top Local $iChannels = 4 Local $hWnd = _WinAPI_GetDesktopWindow() Local $hDesktopDC = _WinAPI_GetDC($hWnd) Local $hMemoryDC = _WinAPI_CreateCompatibleDC($hDesktopDC) ;create compatible memory DC Local $tBIHDR = DllStructCreate($tagBITMAPINFO) $tBIHDR.biSize = DllStructGetSize($tBIHDR) $tBIHDR.biWidth = $biWidth $tBIHDR.biHeight = -$biHeight $tBIHDR.biPlanes = 1 $tBIHDR.biBitCount = $iChannels * 8 Local $aDIB = DllCall("gdi32.dll", "ptr", "CreateDIBSection", "hwnd", 0, "struct*", $tBIHDR, "uint", 0, "ptr*", 0, "ptr", 0, "dword", 0) _WinAPI_SelectObject($hMemoryDC, $aDIB[0]) Local $tBits = DllStructCreate('byte[' & $biWidth * $biHeight * $iChannels & ']', $aDIB[4]) _WinAPI_BitBlt($hMemoryDC, 0, 0, $biWidth, $biHeight, $hDesktopDC, $iLeft, $iTop, $SRCCOPY) _OpenCV_DLLOpen("libemgucv-windesktop-4.5.2.4673\libs\x64\cvextern.dll") Local $matImg = _cveMatCreateWithData($biHeight, $biWidth, $CV_8UC4, $tBits, 0) _cveImshowMat("Screen capture", $matImg) _cveWaitKey(0) _WinAPI_DeleteObject($aDIB[0]) $tBIHDR = 0 _WinAPI_DeleteDC($hMemoryDC) _WinAPI_ReleaseDC($hWnd, $hDesktopDC) _cveMatRelease($matImg) _cveDestroyWindow("Screen capture") _Opencv_DLLClose() Func _WinAPI_GetDesktopScreenRect() Local $iRight, $iBottom, $aRetrun Local $tRect = DllStructCreate($tagRECT) $tRect.Left = 0 $tRect.Top = 0 $tRect.Right = -1 $tRect.Bottom = -1 Local Const $tagDISPLAY_DEVICE = "dword Size;wchar Name[32];wchar String[128];dword Flags;wchar ID[128];wchar Key[128]" Local $tDisplayDevice = DllStructCreate($tagDISPLAY_DEVICE) $tDisplayDevice.Size = DllStructGetSize($tDisplayDevice) Local $tDisplaySettings = DllStructCreate($tagDEVMODE_DISPLAY) $tDisplaySettings.Size = DllStructGetSize($tDisplaySettings) Local $iDevNum = 0 While 1 ; _WinAPI_EnumDisplayDevices("", $iDevNum) $aRetrun = DllCall("user32.dll", "int", "EnumDisplayDevicesW", "ptr", 0, "dword", $iDevNum, "struct*", $tDisplayDevice, "dword", 1) If Not $aRetrun[0] Then ExitLoop $iDevNum += 1 If BitAND($tDisplayDevice.Flags, $DISPLAY_DEVICE_MIRRORING_DRIVER) Or Not BitAND($tDisplayDevice.Flags, $DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) Then ContinueLoop EndIf If BitAND($_cve_debug, 1) Then ConsoleWrite($tDisplayDevice.Name & @TAB & "Attached to desktop: " & (BitAND($tDisplayDevice.Flags, $DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) <> 0) & @CRLF) ConsoleWrite($tDisplayDevice.Name & @TAB & "Primary: " & (BitAND($tDisplayDevice.Flags, $DISPLAY_DEVICE_PRIMARY_DEVICE) <> 0) & @CRLF) ConsoleWrite($tDisplayDevice.Name & @TAB & "Mirroring driver: " & (BitAND($tDisplayDevice.Flags, $DISPLAY_DEVICE_MIRRORING_DRIVER) <> 0) & @CRLF) ConsoleWrite($tDisplayDevice.Name & @TAB & "VGA compatible: " & (BitAND($tDisplayDevice.Flags, $DISPLAY_DEVICE_VGA_COMPATIBLE) <> 0) & @CRLF) ConsoleWrite($tDisplayDevice.Name & @TAB & "Removable: " & (BitAND($tDisplayDevice.Flags, $DISPLAY_DEVICE_REMOVABLE) <> 0) & @CRLF) ConsoleWrite($tDisplayDevice.Name & @TAB & "More display modes: " & (BitAND($tDisplayDevice.Flags, $DISPLAY_DEVICE_MODESPRUNED) <> 0) & @CRLF) ConsoleWrite(@CRLF) Endif ; _WinAPI_EnumDisplaySettings($tDisplayDevice.Name, $ENUM_CURRENT_SETTINGS) Local $sDevice = $tDisplayDevice.Name Local $sTypeOfDevice = 'wstr' If Not StringStripWS($sDevice, $STR_STRIPLEADING + $STR_STRIPTRAILING) Then $sTypeOfDevice = 'ptr' $sDevice = 0 EndIf $aRetrun = DllCall("user32.dll", "bool", "EnumDisplaySettingsW", $sTypeOfDevice, $sDevice, "dword", $ENUM_CURRENT_SETTINGS, "struct*", $tDisplaySettings) If Not $aRetrun[0] Then ContinueLoop If $tRect.Left > $tDisplaySettings.X Then $tRect.Left = $tDisplaySettings.X If $tRect.Top > $tDisplaySettings.Y Then $tRect.Left = $tDisplaySettings.Y $iRight = $tDisplaySettings.X + $tDisplaySettings.PelsWidth If $tRect.Right < $iRight Then $tRect.Right = $iRight $iBottom = $tDisplaySettings.Y + $tDisplaySettings.PelsHeight If $tRect.Bottom < $iBottom Then $tRect.Bottom = $iBottom WEnd $tDisplaySettings = 0 $tDisplayDevice = 0 Return $tRect EndFunc ;==>_WinAPI_GetDesktopScreenRect1 point
-
Security questions for AutoIT approval
TheDcoder reacted to argumentum for a topic
lol, anyone that can not answer these questions by him/her self, should not be doing that job, as THAT is not the way to get those answers. There. A free lesson. ( Do click like -or HaHa- if you get to read this )1 point -
confused by WinGetTitle
636C65616E reacted to Nine for a topic
Current Alpha version has resolved that issue1 point -
What have you tried? Completely untested, but I suspect it should look something like this -- Local $sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "prefs": {"download.default_directory": "c:\\your\\desired\\directory\\"}}}}}'1 point