Leaderboard
Popular Content
Showing content with the highest reputation on 02/12/2021 in all areas
-
All you guys are just nerds. And I'd like to invite you to TheDcoder's BIG Breakfast, where you can gobble up his resources as much as you like .... he's got plenty. P.S. And don't forget to put all your plastic wrappers in his Wrapper Pile, which he feeds back into his Resource Maker machine.2 points
-
EasyCodeIt - cross-platform AutoIt implementation
argumentum and one other reacted to JockoDundee for a topic
What’s your CPU utilization when booting, 100%? During booting, (which is what we were talking about), programs have to be loaded before they can even run, so... It says 18:34.877<bootloader failure E756-AF00 - cannot stat iOS config missing or unreadable> 18:34:887<bootloader unable to start at segment 0000:0000 - but damn that SSD is smokin’ fast>2 points -
Hi @SEuBo. Thanks! happy to know you like it. Pretty cool idea. I've got work in progress for adding ROT functionality with my AutoObject_Internal, so if i work out the kinks, you won't need AutoItObject also I can't seem to reproduce the problems you seem to describe (tested on win10). IPC with AutoObject_Internal is unstable and very unpredictable currently. Your usage, besides using it between processes seems to be fine While current version is mostly stable, many edge cases makes the code more like a beta release currently. The issue for me is shallow COM interface documentation from MSDN and not many seems to report errors with the project (if more than a handful of people are using it). My best guesses currently for the problem would be: The reference count may reach 0 and trigger the object to release the memory (a bug with IPC i am looking into) Currently i return no info from the TypeInfo part of IDispatch interface. This seems to cause no problems most of the time, but i suspect it may be the cause for crashes in some cases. I will be happy to try and look into it, if I'm able to reproduce the bug reliably2 points
-
Actually it does, even if you have a beast of a machine, it is akin to using disposable plastics, in the short term the gains look awesome with no apparent losses, but in the long term we will be craving for more and there won't be enough resources... as they are finite... assuming we don't just leave poor old earth and turn it into a dumpster And I am against the ideology of gobbling up resources like breakfast because there is plenty available, there must be a level of efficiently that should be maintained to provide the best resource:utility ratio for a piece of hardware. Older hardware and current low-budget hardware is no good for anything besides very light usage of computers, i.e basically browsing the internet. I can 100% attest to the fact that the storage medium is much bigger bottleneck compared to the speed of modern CPUs, my laptop was slow to boot and run programs but when I added in a SDD everything suddenly became quicker, boot time dropped down from more than a minute to less than 30 seconds! It currently matches the signal timeout for my external monitor, so by the time my monitor shows "there is no signal" my laptop is already booted up and ready. Maybe I should disable the wait time in my boot menu?2 points
-
I have a problem with WinHttp..
FrancescoDiMuro reacted to Nine for a topic
Of course, but that is working ? No ?1 point -
Now the JavaScript code works. But the Communication example still doesn't work. The Invoke method of the CoreWebView2WebMessageReceivedEventHandler callback interface isn't called and a COM error is generated when the script exits. For the time being, let's leave this problem alone. The Getting started examples except the Communication example can be found in the 7z-file at bottom of this post. Now we've more or less been through all the Getting started examples. How do we get on from here?1 point
-
removing unused #include?
RTFC reacted to Earthshine for a topic
https://www.google.com/search?q=redundant&ie=UTF-8&oe=UTF-8&hl=en-us&client=safari Honestly I’m tired of reading your mindless drivel. You know what he meant as did we all but you like to misconstrue stuff in your twisted views that you may think is logic. Please stop adjective not or no longer needed or useful; superfluous. "many of the old skills had become redundant"1 point -
If @error
pixelsearch reacted to Musashi for a topic
@Marcel2304 : These tips are really important. Even if a function like e.g. ConsoleWrite does not provide an error code (according to the help), @error will be reseted. Example : ; 1 : FileRead(@ScriptDir & "\blabla.txt") ; <-- a file, that does not exist ConsoleWrite("Error = " & @error & @CRLF & @CRLF) ; <-- Error = 1 ; 2 : FileRead(@ScriptDir & "\blabla.txt") ; <-- a file, that does not exist ConsoleWrite("Output :" & @CRLF) ConsoleWrite("Error = " & @error & @CRLF & @CRLF) ; <-- Error = 0 ; 3 : save @error in a var (mentioned by @pixelsearch): Local $iError FileRead(@ScriptDir & "\blabla.txt") ; <-- a file, that does not exist $iError = @error ConsoleWrite("Output :" & @CRLF) ConsoleWrite("Error = " & $iError & @CRLF) ; <-- Error = 11 point -
If @error
Musashi reacted to pixelsearch for a topic
In all scripts, the best way to avoid all this headache is to transfer @error in a variable, immediately after the line you want to test if it succeeded or not, for example : Global $test = RunWait(...) $iKeep_error = @error ; now you can check $iKeep_error wherever you like1 point -
1 point
-
? about the syntax should be like this: $oCoreWebView2.AddScriptToExecuteOnDocumentCreated("window.chrome.webview.addEventListener('message', event => alert(event.data)); window.chrome.webview.postMessage(window.document.URL);", Null) sorry, edit after a check: don't ask me why, but I've seen that it works if you remove the ".chrome.webview" part, that is, like this: $oCoreWebView2.AddScriptToExecuteOnDocumentCreated("window.addEventListener('message', event => alert(event.data)); window.postMessage(window.document.URL);", Null)1 point
-
Where should I Start Autolt - (Locked)
FrancescoDiMuro reacted to JockoDundee for a topic
That actually is a good place to end your job - check out the forum rules.1 point -
SEuBo, No, the default is NOT to allow compiled scripts to run other scripts - from the Help file: M231 point
-
Probleme with ImageSearch
FrancescoDiMuro reacted to Musashi for a topic
@junkew : Just a friendly note in case you missed the other threads by @YuChan . Take a look at : https://www.autoitscript.com/forum/topic/205094-one-gui-who-follow-mouse/?do=findComment&comment=1474709 https://www.autoitscript.com/forum/topic/205096-mouse-position/?do=reportComment&comment=1474661 You're probably wasting your precious time to a person, who doesn't deserve it .1 point -
EasyCodeIt - cross-platform AutoIt implementation
E1M1 reacted to JockoDundee for a topic
It’s not totally Software’s fault. Over half a century ago, Software and Hardware made a secret pact to extract the maximum $$ possible from the lowly End-Losers. Software said, I promise to continually enhance, extend, and otherwise adopt any and all features, capabilities, protocols, file formats, api’s that are almost available into one monolithic, indistinguishable, all-in-one .exe file. A product that would generally not be fit for running on anything less than the next years SOA hardware. Hardware said, And I promise to likewise to provide such hardware, replete with ever increasing MHz and GHz and GB and TB, and of course a full assortment of inscrutable buzzwords to describe the endless, if banal variations on the NP junction that has served us for so long. Taken together, our actions will insure that no one will ever be fully satisfied with their current system, no matter how powerful, but will feel that they are on the cusp of obtaining such a setup, if only with their next purchase. And for those who gamely fight us by holding on to their ancient programs and obsolete hardware, they will face in the inexorable onslaught of the dual indignities of discontinued hardware and End-Of-Life software support. Alas, Hardware lets us all down, as I type this from a 12 year-old Intel i7 that is still widely available today. So...:)1 point -
removing unused #include?
Earthshine reacted to RTFC for a topic
Maybe look up the definition of "redundant"?1 point -
Error: Variable must be of type object - (Locked)
Earthshine reacted to Jos for a topic
I am in for a joke but there is a time & place for them, and this is not one of them...... ... SO ALL OTHERs: please stay out until the thread is cleared ! (sad this last line is needed each time to make it clear)1 point -
Thank you @LarsJ for your suggestion I copied the dlls into the autoit path, but again without success, however I think I have found the reason for the problem: 1) after copying the 2 dll to the autoit path, the error kept occurring 2) I tried to set #RequireAdmin on the script and, at this point, the following new error window appeared: "Microsoft Edge cannot read and write to the data directory: C:\ Program Files (x86) \ AutoIt3 \ autoit3_x64.exe.WebView2 \ EBWebView" so the problem is that the AutoIt3 directory doesn't have write permission for local users. That's all. it is not necessary to copy the DLLs to a location other than the script path. my solution has been to set write/modify permissions to the AutoIt3 folder so to allow the script to create its own subfolder (on first run). Once the subfolder was created, I restored the previous permission to the AutoIt3 folder and allowed the write/modify permission only to the newly created autoit3_x64.exe.WebView2 folder This way everything works fine (... so far ...) Thanks again for your tips P.S. @LarsJ This WebView2 script you wrote is elite. I tried to study it and I see that you have for example also used portions of code (Func ObjectFromTag) that I had already seen (with awe) created by the queen of developers @trancexx in this other post. But, now as then I must give up trying to understand. This type of code intimidates me, too complex for my poor understanding of the inner workings of Windows. However I like to see powerful code like this appear on the forum thanks to programmers, like you and many others, who master these intricacies with great ease. Thanks again1 point
-
removing unused #include?
Earthshine reacted to Jos for a topic
The savings mainly come from the #included files which sub include a lot of other files.1 point -
removing unused #include?
Earthshine reacted to Jos for a topic
Au3stripper will simply strip anything that isn't necessary.1 point -
removing unused #include?
Earthshine reacted to RTFC for a topic
CodeScanner will produce a list of redundant #includes.1 point -
To start you up with UIAutomation : #NoTrayIcon #include "Includes\CUIAutomation2.au3" #include <Constants.au3> Opt ("MustDeclareVars", 1) _Systray_SelectOption() Func _Systray_SelectOption() Local $hWnd = WinGetHandle('[Class:Shell_TrayWnd]') If Not $hWnd Then Return SetError(1) Local $hCtrl = ControlGetHandle($hWnd, '', "ToolbarWindow323") If Not $hCtrl Then Return SetError(2) ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation) If Not IsObj($oUIAutomation) Then Return ConsoleWrite("$oUIAutomation ERR" & @CRLF) ConsoleWrite("$oUIAutomation OK" & @CRLF) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement($pDesktop) $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oDesktop) Then Return ConsoleWrite("$oDesktop ERR" & @CRLF) ConsoleWrite("$oDesktop OK" & @CRLF) ; Get element by handle Local $pElement, $oElement $oUIAutomation.ElementFromHandle($hCtrl, $pElement) $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF) ConsoleWrite("$oElement OK" & @CRLF) ; Get condition (ControlType = Button) Local $pCondition, $oCondition $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition) $oCondition = ObjCreateInterface($pCondition, $sIID_IUIAutomationPropertyCondition, $dtagIUIAutomationPropertyCondition) If Not IsObj($oCondition) Then Return ConsoleWrite("$oCondition ERR" & @CRLF) ConsoleWrite("$oCondition OK" & @CRLF) ; Find all buttons Local $pElementArray, $oElementArray, $iElements $oElement.FindAll($TreeScope_Children, $oCondition, $pElementArray) $oElementArray = ObjCreateInterface($pElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray) $oElementArray.Length($iElements) If Not IsObj($oElementArray) Then Return ConsoleWrite("$oElementArray ERR" & @CRLF) ConsoleWrite("$oElementArray OK" & @CRLF) ; Get array of buttons Local $aElements[$iElements] For $i = 0 To $iElements - 1 $oElementArray.GetElement($i, $pElement) $aElements[$i] = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) Next ; Get name and position for each button Local $vValue, $bFound = False Local $tPoint = DllStructCreate("long X;long Y"), $bBool For $i = 0 To UBound($aElements) - 1 $aElements[$i].GetCurrentPropertyValue($UIA_NamePropertyId, $vValue) ConsoleWrite("Name:" & $vValue & @CRLF) $aElements[$i].GetClickablePoint ($tPoint, $bBool) If StringRegExp ($vValue, "\(\d{1,3}.%\)") Then MouseClick ("left", $tPoint.X, $tPoint.Y, 1, 1) $bFound = True ExitLoop EndIf Next Sleep (1500) $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Windows.UI.Core.CoreWindow", $pCondition ) If Not $pCondition Then Return ConsoleWrite( "$pCondition ERR" & @CRLF ) ConsoleWrite( "$pCondition OK" & @CRLF ) Local $pPower, $oPower $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition, $pPower ) $oPower = ObjCreateInterface( $pPower, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oPower ) Then Return ConsoleWrite( "$oPower ERR" & @CRLF ) ConsoleWrite( "$oPower OK" & @CRLF ) $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Slider", $pCondition) $oCondition = ObjCreateInterface($pCondition, $sIID_IUIAutomationPropertyCondition, $dtagIUIAutomationPropertyCondition) If Not IsObj($oCondition) Then Return ConsoleWrite("$oCondition ERR" & @CRLF) ConsoleWrite("$oCondition OK" & @CRLF) $oPower.FindFirst($TreeScope_Children, $oCondition, $pElement) $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF) ConsoleWrite("$oElement OK" & @CRLF) Local $tRect = DllStructCreate("long Left;long Top;long Right;long Bottom") $oElement.CurrentBoundingRectangle($tRect) ConsoleWrite(" L:" & $tRect.Left & " T:" & $tRect.Top & " R:" & $tRect.Right & " B:" & $tRect.Bottom & @CRLF) Local $x = $tRect.Left + Int(($tRect.Right-$tRect.Left)*.5) ; calculate center of slider Local $y = $tRect.Top + Int(($tRect.Bottom-$tRect.Top)*.75) MouseClick ("left", $x, $y, 1, 1) EndFunc1 point
-
Recently a user asked given two keyboards how to determine which keyboard was pressed this is the start of such functionality I was already given permission to post this example by a moderator before I bothered ;Bilgus 2018 ;Determine which keyboard was pressed #include <Array.au3> #include <WinAPISys.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global Const $HWND_MESSAGE = (-3) ;create a message-only window when set as Parent ;RAWINPUTDEVICE Constants Global Const $HID_USAGE_PAGE_GENERIC = 0x1 Global Const $HID_USAGE_GENERIC_KEYBOARD = 0x6 Global $ghSelectedDevice Global $gaKeyboards = EnumRawKeyboards("\HID") If IsArray($gaKeyboards) And $gaKeyboards[0][0] >= 1 Then $ghSelectedDevice = $gaKeyboards[1][0] ; hard coded change to suit _ArrayDisplay($gaKeyboards, '_WinAPI_EnumRawInputDevices', "", 0, Default, "Handle|Type|VID|Keys") ;Not Needed... Global $hTarget = GUICreate("main", 10, 10, Default, Default, Default, Default, $HWND_MESSAGE) ;Dummy window to recieve messages Register_RawInput($HID_USAGE_PAGE_GENERIC, $HID_USAGE_GENERIC_KEYBOARD, $RIDEV_INPUTSINK, $hTarget) ;$RIDEV_INPUTSINK recieves input when not foreground ; Register WM_INPUT message GUIRegisterMsg($WM_INPUT, 'WM_INPUT') HotKeySet("{ESC}", _Exit) While 1 Sleep(1000) WEnd Func Device_Pressed() ConsoleWrite("Device Pressed" & @CRLF) EndFunc ;==>Device_Pressed Func _Exit() Exit EndFunc ;==>_Exit Func Register_RawInput($iUsagePage, $iUsage, $iFlags, $hTargetHwnd) Local $tRID = DllStructCreate($tagRAWINPUTDEVICE) DllStructSetData($tRID, 'UsagePage', $iUsagePage) DllStructSetData($tRID, 'Usage', $iUsage) DllStructSetData($tRID, 'Flags', $iFlags) DllStructSetData($tRID, 'hTarget', $hTargetHwnd) ; Register HID input to obtain info from devices _WinAPI_RegisterRawInputDevices($tRID) EndFunc ;==>Register_RawInput Func WM_INPUT($hWnd, $iMsg, $wParam, $lParam) ;Callback from RawInput #forceref $iMsg, $wParam ;'struct;dword Type;dword Size;handle hDevice;wparam wParam;endstruct' Local $tRIH = DllStructCreate($tagRAWINPUTHEADER) If _WinAPI_GetRawInputData($lParam, $tRIH, DllStructGetSize($tRIH), $RID_HEADER) And DllStructGetData($tRIH, "Type") = $RIM_TYPEKEYBOARD Then ConsoleWrite("0x" & Hex(DllStructGetData($tRIH, "hDevice")) & @CRLF) If $ghSelectedDevice = DllStructGetData($tRIH, "hDevice") Then Device_Pressed() Else ;Different Device ConsoleWrite("Different Device Pressed" & @CRLF) EndIf EndIf Return $GUI_RUNDEFMSG ;Pass on to default winproc EndFunc ;==>WM_INPUT Func EnumRawKeyboards($sDeviceNameMatch = "") ;Returns array of keyboard device IDs Local $tInfo, $aData = _WinAPI_EnumRawInputDevices() If IsArray($aData) Then Local $aKeyboards[$aData[0][0] + 1][4] ;'dword Size;dword Type;';'struct;dword KbType;dword KbSubType;dword KeyboardMode;dword NumberOfFunctionKeys;dword NumberOfIndicators;dword NumberOfKeysTotal;endstruc' Local $_tagRID_INFO_KEYBOARD = $tagRID_INFO_KEYBOARD If StringRight($_tagRID_INFO_KEYBOARD, 1) <> "t" Then $_tagRID_INFO_KEYBOARD &= "t" ; t is missing from endstruct Local $iCt = 0, $iSz Local $tInfo, $tDeviceName, $sDeviceName For $i = 1 To $aData[0][0] $tInfo = DllStructCreate($_tagRID_INFO_KEYBOARD) If _WinAPI_GetRawInputDeviceInfo($aData[$i][0], $tInfo, DllStructGetSize($tInfo), $RIDI_DEVICEINFO) And $aData[$i][1] = $RIM_TYPEKEYBOARD Then $iSz = _WinAPI_GetRawInputDeviceInfo($aData[$i][0], 0, 0, $RIDI_DEVICENAME) ;Get bytes needed $tDeviceName = DllStructCreate('wchar[' & $iSz + 1 & ']') ;Holds device name string If _WinAPI_GetRawInputDeviceInfo($aData[$i][0], $tDeviceName, DllStructGetSize($tDeviceName), $RIDI_DEVICENAME) Then $sDeviceName = DllStructGetData($tDeviceName, 1) If $sDeviceNameMatch <> "" And Not StringInStr($sDeviceName, $sDeviceNameMatch) Then ContinueLoop $iCt += 1 $aKeyboards[$iCt][0] = $aData[$i][0] ;Handle $aKeyboards[$iCt][1] = $aData[$i][1] ;Type $aKeyboards[$iCt][2] = $sDeviceName $aKeyboards[$iCt][3] = DllStructGetData($tInfo, "NumberOfKeysTotal") EndIf EndIf Next $aKeyboards[0][0] = $iCt ; Write count of keyboard devices to array ReDim $aKeyboards[$iCt + 1][4] ;Resize array EndIf Return $aKeyboards EndFunc ;==>EnumRawKeyboards1 point
-
Automating Notepad with Sample code - step by step This is a repetition of the Notepad example above. But this time, the possibilities for creating Sample code in UIASpy will be exploited. Only the first part of the example will be reviewed once more in detail. But the pictures will not be repeated. So please open the previous example in a new tab in the browser. Open "Examples\Notepad\Windows 7, 10\2) Sample code - step by step\Notepad.au3" (empty) in SciTE. The file is included in the zip-file in bottom of first post. Open UIASpy (also included in zip-file) and keep UIASpy open throughout the entire example. Open Left pane main menu and click Delete top windows to delete all treeview windows except Desktop. First step is to add initial code to create the UI Automation object and the Desktop element. Open Sample code main menu in UIASpy and click Initial code. Open the menu once more and click Corrections to get an idea of the corrections that have to be made to this generic code. Paste the code from clipboard into SciTE (Shift+Insert). The code should look like this: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "CUIAutomation2.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) EndFunc ; Code corrections: ; CUIAutomation2.au3 path ; Code to open target appl ; Create undeclared variables ; Delete double declared variables ; Correct $pWindow, $pParent and $pControl names ; Correct $oWindow, $oParent and $oControl names Correct the path to CUIAutomation2.au3. Add code to open Notepad. Delete correction comments. Now the code should look like this: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\..\Includes\CUIAutomation2.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Open Notepad Run( "Notepad" ) Sleep( 1000 ) ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) EndFunc Run the code with F5 and leave Notepad open. Check that SciTE output is OK. Next step is to get the Notepad window as an UI Automation element. Place mouse cursor over Notepad title bar and press F2. Select the row in the Notepad detail information listview page in UIASpy that matches the row with the red arrow in the first picture in the previous example. Right-click and click Clear sample code in the context menu. Right-click once more and click Create sample code. Open Sample code main menu and click Corrections to get an idea of the corrections that have to be made to the code. Paste the code from clipboard into SciTE as the very last code (after EndFunc). The code should look like this: ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow, $oWindow $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pWindow ) $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow ) Then Return ConsoleWrite( "$oWindow ERR" & @CRLF ) ConsoleWrite( "$oWindow OK" & @CRLF ) ; Code corrections: ; CUIAutomation2.au3 path ; Code to open target appl ; Create undeclared variables ; Delete double declared variables ; Correct $pWindow, $pParent and $pControl names ; Correct $oWindow, $oParent and $oControl names Replace "window/control" with "Notepad window". Replace "Window" with "Notepad". Delete correction comments. Move code into function: ; --- Find Notepad window --- ConsoleWrite( "--- Find Notepad window ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pNotepad, $oNotepad $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pNotepad ) $oNotepad = ObjCreateInterface( $pNotepad, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oNotepad ) Then Return ConsoleWrite( "$oNotepad ERR" & @CRLF ) ConsoleWrite( "$oNotepad OK" & @CRLF ) Close the previous Notepad, run the code and leave Notepad open. Check that SciTE output is OK. Third step is to fill out the Edit control with "HelloWorld". An UI Automation task is almost always done in two or three steps: 1. Create condition to find element 2. Find the UI Automation element 3. Extract info or perform action Each of these steps can usually be done in 1 - 3 lines of UI Automation code. All three steps can usually be done in less that 10 lines of UI Automation code (common AutoIt debug/info code not included). To get the Notepad window above we only used two steps. Place mouse cursor in the Edit control in Notepad and press F1. Select the row in the Edit detail information listview page in UIASpy that matches the row with the red arrow in the second picture in the previous example. Right-click and click Clear sample code in the context menu. Right-click once more and click Create sample code. Open Sample code main menu and click Corrections to get an idea of the corrections that have to be made to the code. Paste the code from clipboard into SciTE as the very last code (after EndFunc). The code should look like this: ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "15", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pEdit, $oEdit $oParent.FindFirst( $TreeScope_Descendants, $pCondition0, $pEdit ) $oEdit = ObjCreateInterface( $pEdit, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit ) Then Return ConsoleWrite( "$oEdit ERR" & @CRLF ) ConsoleWrite( "$oEdit OK" & @CRLF ) ; Code corrections: ; CUIAutomation2.au3 path ; Code to open target appl ; Create undeclared variables ; Delete double declared variables ; Correct $pWindow, $pParent and $pControl names ; Correct $oWindow, $oParent and $oControl names Replace "Find window/control" with "Fill Edit control". Delete the line "Local $pCondition0". Replace "$oParent" with "$oNotepad". Delete correction comments. Move code into function: ; --- Fill Edit control --- ConsoleWrite( "--- Fill Edit control ---" & @CRLF ) $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "15", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pEdit, $oEdit $oNotepad.FindFirst( $TreeScope_Descendants, $pCondition0, $pEdit ) $oEdit = ObjCreateInterface( $pEdit, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit ) Then Return ConsoleWrite( "$oEdit ERR" & @CRLF ) ConsoleWrite( "$oEdit OK" & @CRLF ) Close the previous Notepad, run the code and leave Notepad open. Check that SciTE output is OK. Place mouse cursor in the Edit control in Notepad and press F1. If there is a red (invalid) Notepad window in the treeview then delete it (Right-click the red element and click Delete element and all childs). Scroll down to the Control Patterns (element actions) section in the Edit detail information listview page in UIASpy. Select the row "$UIA_IsValuePatternAvailablePropertyId" that matches the row with the red arrow in the third picture in the previous example. Right-click and click Clear sample code in the context menu. Right-click once more and click Create sample code. Click the Edit item in the treeview to return to the Edit detail information listview page. Scroll down to the bottom of the listview page. The Value Pattern Methods subsection should be visible. Select the row with the SetValue(bstr) method in second column: Right-click and click Create sample code (don't clear the code this time). Paste the code from clipboard into SciTE as the very last code (after EndFunc). The code should look like this: ; --- Value Pattern (action) Object --- ConsoleWrite( "--- Value Pattern (action) Object ---" & @CRLF ) Local $pValuePattern, $oValuePattern $oEdit.GetCurrentPattern( $UIA_ValuePatternId, $pValuePattern ) $oValuePattern = ObjCreateInterface( $pValuePattern, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oValuePattern ) Then Return ConsoleWrite( "$oValuePattern ERR" & @CRLF ) ConsoleWrite( "$oValuePattern OK" & @CRLF ) ; --- Value Pattern (action) Methods --- ConsoleWrite( "--- Value Pattern (action) Methods ---" & @CRLF ) $oValuePattern.SetValue(bstr) Delete the two comments, two ConsoleWrites and empty lines. Replace "bstr" with "HelloWorld". Move code into function: Local $pValuePattern, $oValuePattern $oEdit.GetCurrentPattern( $UIA_ValuePatternId, $pValuePattern ) $oValuePattern = ObjCreateInterface( $pValuePattern, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oValuePattern ) Then Return ConsoleWrite( "$oValuePattern ERR" & @CRLF ) ConsoleWrite( "$oValuePattern OK" & @CRLF ) $oValuePattern.SetValue( "HelloWorld" ) Close the previous Notepad, run the code, check that SciTE output is OK, check "HelloWorld" in Notepad Edit control. All code after the third step: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\..\Includes\CUIAutomation2.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Open Notepad Run( "Notepad" ) Sleep( 1000 ) ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find Notepad window --- ConsoleWrite( "--- Find Notepad window ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pNotepad, $oNotepad $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pNotepad ) $oNotepad = ObjCreateInterface( $pNotepad, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oNotepad ) Then Return ConsoleWrite( "$oNotepad ERR" & @CRLF ) ConsoleWrite( "$oNotepad OK" & @CRLF ) ; --- Fill Edit control --- ConsoleWrite( "--- Fill Edit control ---" & @CRLF ) $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "15", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pEdit, $oEdit $oNotepad.FindFirst( $TreeScope_Descendants, $pCondition0, $pEdit ) $oEdit = ObjCreateInterface( $pEdit, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit ) Then Return ConsoleWrite( "$oEdit ERR" & @CRLF ) ConsoleWrite( "$oEdit OK" & @CRLF ) Local $pValuePattern, $oValuePattern $oEdit.GetCurrentPattern( $UIA_ValuePatternId, $pValuePattern ) $oValuePattern = ObjCreateInterface( $pValuePattern, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oValuePattern ) Then Return ConsoleWrite( "$oValuePattern ERR" & @CRLF ) ConsoleWrite( "$oValuePattern OK" & @CRLF ) $oValuePattern.SetValue( "HelloWorld" ) EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find Notepad window --- $pCondition0 OK $oNotepad OK --- Fill Edit control --- $pCondition0 OK $oEdit OK $oValuePattern OK1 point
-
How to restrict inputboxes to specific characters only?
Professor_Bernd reacted to ViciousXUSMC for a topic
I was working on this a while back, wanted to make it a UDF but never put the time to write it to standards. I used it for quite a few things however. #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Test GUI", 618, 276, 192, 124) $Label1 = GUICtrlCreateLabel("Test GUI", 168, 24, 47, 17) $Button1 = GUICtrlCreateButton("Toggle Validation", 290, 24, 110, 40) $Input1 = GUICtrlCreateInput("Max 10 Characters", 40, 72, 553, 21) $Input2 = GUICtrlCreateInput("Numb3rs 0nly", 40, 97, 553, 21) $Edit1 = GUICtrlCreateEdit("Max 10 Chars Numbers Only + Auto Line Break", 40, 120, 553, 105) GUISetState(@SW_SHOW) $iToggle = 1 While 1 Sleep(10) If Mod($iToggle, 2) = 0 Then ;Example 1 Limit to 10 Characters _GUIRegExValidate($Input1, "(.{10})(.)", "$1") ;Example 2 Can only type numbers _GUIRegExValidate($Input2, "[^\d]", "") ;Example 3 Combind More Than One On Same Input limit to 10 characters, limit to numbers only, line break @ 10 characters to new line _GUIRegExValidate($Edit1, "(.{10})(.)", "$1" & @CRLF) _GUIRegExValidate($Edit1, "[^\d\r\n]", "") EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $iToggle = $iToggle + 1 EndSwitch WEnd Func _GUIRegExValidate($sInputLabel, $sRegExCapture, $sRegExReplace) $Step1Read = GUICtrlRead($sInputLabel) $Step2Validate = StringRegExpReplace($Step1Read, $sRegExCapture, $sRegExReplace) If @Extended = 0 Then Return GUICtrlSetData($sInputLabel, $Step2Validate) EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) _GUIRegExValidate($Edit1, "(.{20})(.)", "$1") EndFunc1 point