Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/17/2015 in all areas

  1. Honestly I don't care much about you at all other than I dislike people going against our forumrules and then still have the balls to post a reply like you just did. Those I have zero tolerance for I will lock all accounts you created except the last one and this better be the last time I have to deal with you because the only mode going forward will be is a permanent ban. So do not open any topic that is even close to game automation. End-of-story Jos
    2 points
  2. Automate all windows and browser applications with one UDF function library. Based on the microsoft automation API this library high level supports Recognition of conttrols from EDGE, Chrome, FF, Opera, Safari and Windows native apps Small testing framework to split object repository from coding away Introduction Quickstart - Getting started quickly Simple scripts With this module you can automate all applications/programs that support ui automation and/or accesibility api from microsoft you can recognize more controls than AutoIT can recognize "out of the box" you can use concepts from other testing frameworks like http://download.freedesktop.org/ldtp/doc/ldtp-tutorial.pdf http://safsdev.sourceforge.net/Default.htm coded ui testing from microsoft Some of those controls / applications are chrome browser (partly mainwindow has to be done with MSAA for navigating) chrome://accessibility in the adress bar of chrome or start with "--force-renderer-accessibility" silverlight controls Ribbon control controlbars of Excel/Word IE and FF browsers Windows Media Player Windows clock AFX .. controls (partly) .... Based on the initial AIO Object I now have made the interface file to work with objCreateInterface function which is in the latest beta's automate clicking and querying basic information It gives you a lot of basic information to be able to automate clicking, querying basic information where it goes further in certain situations than AutoIt is identifying Starting threads for background on the ui automation api of microsoft (not for starters) http://en.wikipedia.org/wiki/Microsoft_UI_Automation http://msdn.microsoft.com/en-us/library/ms747327.aspx Previous threads in general help/support Interface AutoItObject IUIAutomation ObjCreateInterface and struct tagPoint in method ElementFromPoint Be aware that API is not allways installed under XP/Vista see http://support.microsoft.com/kb/971513 Within Windows 7 and Windows 8 it should be preinstalled by default. Be aware on 32 and 64 bits way of running your script #AutoIt3Wrapper_UseX64=Y or N Basic example of usage / showing and retrieving the default information, will post multiple examples later Hover your mouse to an area of interest and press ctrl+w and information will be shown in the edit box of the form Simple spy demo (see simplespy.au3 or use latest ZIP attachment for latest version) Main features Recognize windows and html controls for the major browsers Logical and physical description for controls (UI mapping, Application map) Simple repository logic to abstract logical and physical descriptions Store Runtime Type Information in RTI. variables Rubberbanding/highlighting of objects Simple spy to help in making / identifying the physical description Support of regular expression(s) in identifying objects recognize objects on multiple properties supported properties: name ,title, automationid, classname, class, iaccessiblevalue, iaccessiblechildId, controltype, processid, acceleratorkey The actions provided so far "leftclick", "left", "click", "leftdoubleclick", "leftdouble", "doubleclick", _ "rightclick", "right", "rightdoubleclick", "rightdouble", _ "middleclick", "middle", "middledoubleclick", "middledouble", "mousemove", "movemouse" "setvalue","settextvalue" "setvalue using keys" "setValue using clipboard" "getvalue" "sendkeys", "enterstring", "type", "typetext" "invoke" "focus", "setfocus", "activate" "close" "move","setposition" "resize" "minimize", "maximize", "normal", "close", "exist", "exists" "searchcontext", "context" "highlight" "getobject","object" "attach" "capture","screenshot", "takescreenshot" "dump", "dumpthemall" "propertyvalue", "property" match on multiple properties like: name:=((Zoeken.*)|(Find.*)); ControlType:=Button; acceleratorkey:=Ctrl+F Support for 117 different properties see $UIA_propertiesSupportedArray in uiawrappers like for example title, regexptitle, class, regexpclass, iaccessiblevalue, iaccessiblechildid, name, accesskey, automationid, classname IAccessible, IAccessible2, ISimpleDom interfaces debuglogging to a file log.txt (no output in scitewindow) Examples Example 1 Iterating thru the different ways of representing the objects in the tree (#comment-1105548) Example 2 Finding the taskbar and clicking on the start menu button (#comment-1105680) Example 3 Clicking a litlle more and in the end displaying all items from the clock (thats not directly possible with AU3Info) (#comment-1108849) Example 4 that demonstrates the calculator Example 5 Automating chrome Example 6 Demonstrates all stuff within chrome to navigate html pages, find hyperlink, click hyperlink, find picture, click picture, enter data in inputbox Example 7 The chrome example modified to a firefox example Example 8 The other major browser Internet Explorer automated (made on Example 6 and 7) Example 9 Windows media player Example 10 Automating mach 3 (AFX windows and other hard to get recognized by AutoIT) Lot of links are broken due to forum upgrade just search for the text like "Example 11 Demonstrate Word, Notepad and Calculator actions" Example 11 Demonstrate Word, Notepad and Calculator actions ... Example 13 Details 1 about the right pane of the windows explorer Example 14 Details 2 about the right pane of the windows explorer Example 15 Details 3 about the right pane of the windows explorer Example 16 Details 4 about the right pane of the windows explorer Example 17 Details 5 about the right pane of the windows explorer WITH CACHING Example 18 Details 6 about the right pane of the windows explorer WITH VIRTUAL ITEMS Example 19 Eventhandling examples Example 20 Eventhandling examples Example 21a Eventhandling examples Internet Explorer Example 21b Eventhandling examples Internet Explorer Example 22 Eventhandling examples Follow focus Example 23 Eventhandling examples structure changed Example 24 Eventhandling examples IUIAutomationEventHandler Example 25 SAFEARRAYS Example 26 IACCESSIBLE / MSAA Example 27 IACCESSIBLE2 / MSAA Example 28 IACCESSIBLE / MSAA events Example 29 IACCESSIBLE2 events Example 30 ISimpleDOM Example 31 Notepad window move, maximize, minimize Example 32 Three browsers doing the same stuff with small differences in scripting only .. TODO Build recorder Enhance the spy with a nicer UI UI for the repository (now in the script with dot notation) Enhance mapping / identifying on multiple properties instead of 1 combined with index If speed becomes an issue use the caching logic of the MS UIA framework Add the other patterns later Generalize the concept of System Under Test of starting the SUT (for testing framework purposes) Remote running of scripts Fix issue on finding within dynamic context ... edit august 18th 2013 initial post Only zip files are needed to download , just unzip in 1 directory edit july 2016 Made V0_63 and examples works with AutoIt v3.3.14 Windows 10 tested Simple spy gives some basic code as a present Chrome latest versions seems to be having issues with IUIAutomation on tabs/buttons of mainwindow use MSAA for accessing tabsheets / buttons more cleanup to be in UDF style More comments in the source see changelog.txt for previous changes edit september 2017 All examples fixed for the IE, Firefox and Chrome browser Some small but essential fixes in UIAWrappers edit april 2018 Enhanced logic on fallback / dynamic search, still not perfect, to slow Retested with latest Chrome, FF, Edge and IE11 and some extensions to show how to get text from the webpage (examples 5,6,7) Some small bugfixes Some comments as given in forum incorporated edit may 2019 Speed enhancements on especially fallback searching UIA.CFG works now in a better way to turn on/off debug, highlighting, debug2file More stable and consistent behavior Internal cleanup and refactoring of bigger functions Checked with W10 (not tested on W7) Added some W10 properties Run with 3.3.14.5 on W10 UIA_V0_51.zip EXAMPLES_V0_5.zip UIA_V0_63.zip EXAMPLES_V0_63.zip UIA_V0_64.zip EXAMPLES_V0_64.zip EXAMPLES_V0_66.zip UIA_V0_66.zip EXAMPLES_V0_70.zip UIA_V0_70.zip
    1 point
  3. Here a version of a splash text variant using GDI+. Requires AutoIt v3.3.12.0 or higher! Source code download: UDF: _SplashTextEx.au3 (previous downloads: 135) Example: Example1.au3 (previous downloads: 127) Might be useful for someone... Please report any bugs.
    1 point
  4. Depending on the requirements you will need to manage it #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Global $var = 0 $Form1 = GUICreate("Form1", 350, 250, -1, -1) $ListView1 = GUICtrlCreateListView("Header|Header|Header", 0, 0, 350, 200) GuiCtrlCreateListViewItem('White|White|White',$ListView1) GuiCtrlCreateListViewItem('Pink|Green|Pink',$ListView1) GuiCtrlCreateListViewItem('White|White|White',$ListView1) $btn = GuiCtrlCreateButton('button', 20, 210, 50, 25) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btn _GUICtrlListView_SetItemText($ListView1, 1, "Red", 1) EndSwitch WEnd Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") $hListView = GuiCtrlGetHandle($ListView1) Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") Local $iColor If $iItem = 1 Then If $iSubItem = 1 Then $iColor = RGB2BGR(0x00aa00) ; green $text = _GUICtrlListView_GetItemText($hListView, $iItem, 1) If stringInStr($text, "Red") Then $iColor = RGB2BGR(0xFF0000) Else $iColor = RGB2BGR(0xffaaff) ; pink EndIf Else $iColor = RGB2BGR(0xFFFFFF) ; white EndIf DllStructSetData($tCustDraw, "clrTextBk", $iColor) ; background color Return $CDRF_NEWFONT EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func RGB2BGR($iColor) Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF) EndFunc ;==>RGB2BGR()
    1 point
  5. ? #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 350, 250, -1, -1) $ListView1 = GUICtrlCreateListView("Header|Header|Header", 0, 0, 350, 250) GuiCtrlCreateListViewItem('White|White|White',$ListView1) GuiCtrlCreateListViewItem('Pink|Green|Pink',$ListView1) GuiCtrlCreateListViewItem('White|White|White',$ListView1) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") $hListView = GuiCtrlGetHandle($ListView1) Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") Local $iColor, $iColor2 If $iItem = 1 Then If $iSubItem = 1 Then $iColor = RGB2BGR(0x00aa00) ; green Else $iColor = RGB2BGR(0xffaaff) ; pink EndIf Else $iColor = RGB2BGR(0xFFFFFF) ; white EndIf DllStructSetData($tCustDraw, "clrTextBk", $iColor) ; background color Return $CDRF_NEWFONT EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func RGB2BGR($iColor) Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF) EndFunc ;==>RGB2BGR()
    1 point
  6. AndyS01, We had 2 threads running when the Array library was being rewritten - no-one mentioned any problem with the new parameters at any time. We wrote a detailed changelog when the new code was released and explained carefully that certain functions in the library had been seriously amended - we even added a specific page to the Help file to detail these changes. So I totally reject the "cavalier attitude" insult you threw at us (or rather me since I rewrote this particular library) - where were you when all the public consultation was happening?. The Array library has become much more flexible, and able to deal with 1D and 2D arrays, and all it requires is small amount of re-coding to make old scripts compatible. And if you think this is a disaster, how on earth did you manage when all the includes were split in 3.2.12.0? Anyway, if you are going to revert to an earlier AutoIt version because of this pretty small change, then you do not deserve to benefit from any future improvements and certainly have no sympathy from me. M23
    1 point
  7. Yes. As for your other question search the help file for ternary.
    1 point
  8. Standard _StringProper will do the job for the local Windows character set but if you want a Unicode-wide definition of "word" you can have it: look at the code posted in this ticket.
    1 point
  9. jchd

    Little Math bug?

    JohnOne, The problem reveal when you try to express values in decreasing powers of 2, since FP is binary-based. 0.2 = 1/8 + 1/16 + 1/128 + 1/256 + 1/2048 + 1/4096 + 1/32768 + 1/65536 + ... That is: 0.2 = 2-3 + 2-4 + 2-7 + 2-8 + 2-11 + 2-12 + 2-15 + 2-16 + 2-19 + 2-20 + 2-23 + 2-24 ... Hence you can see the binary pattern for this particular value: 0.00110011001100110011......... This pattern is infinite so when stored in a floating-point register or variable, the value is forcibly truncated.
    1 point
  10. Big M will be rising from his slumber any minute, and sort this shit out.
    1 point
  11. That StringSplit() line is wrong, as r and n are separate characters and as the help file says, you should use $STR_ENTIRESPLIT if you want it to be treated as a whole and not individually.
    1 point
  12. Had to download this 32 bit dll from here for it to work. Looks good.
    1 point
  13. You may do it with the UI Automation framework. See first example in post 112.
    1 point
  14. #include <Array.au3> Global $aFirstArray[10][3] = [["Type1", "Subtype1", 10],["Type1", "Subtype2", 20], _ ["Type1", "Subtype3", 30],["Type2", "Subtype4", 40], _ ["Type2", "Subtype5", 50],["Type3", "Subtype5", 60], _ ["Type4", "Subtype6", 70],["Type4", "Subtype7", 80], _ ["Type5", "Subtype8", 90],["Type5", "Subtype9", 100]] _ArrayDisplay($aFirstArray) Global $aSecondArray[0][2] $lasttype = "" $sum = 0 $iType = -1 for $i = 0 to ubound($aFirstArray) - 1 $type = $aFirstArray[$i][0] If $type = $lasttype then _ArrayAdd($aSecondArray , $aFirstArray[$i][1] & "|" & $aFirstArray[$i][2] , 0 , "|") $sum += $aFirstArray[$i][2] Else If $iType <> -1 Then $aSecondArray[$iType][1] = $sum $sum = 0 $iType = _ArrayAdd($aSecondArray , $aFirstArray[$i][0]) _ArrayAdd($aSecondArray , $aFirstArray[$i][1] & "|" & $aFirstArray[$i][2] , 0 , "|") $sum += $aFirstArray[$i][2] EndIf If $i = ubound($aFirstArray) - 1 Then $aSecondArray[$iType][1] = $sum $lasttype = $type next _ArrayDisplay($aSecondArray, "To This")
    1 point
  15. Some sort of usage explanation usually accompanies an example script..
    1 point
  16. He would have found that if he'd bothered to search
    1 point
  17. BrewManNH

    Adding Text

    Sorry about the post above, lack of proper testing on my part. This script will not overwrite the text in the file, but will add the new text above it. ;~ #include <FileConstants.au3> #include <File.au3> $sFilename = @ScriptDir & "\Test.txt" $hFile = FileOpen($sFilename, 2) ; create new file For $I = 1 To 10000 FileWriteLine($hFile, "Line: " & $I) ; create 10,000 lines of text Next FileClose($hFile) ; close the file ; Only this part is needed to add something to the start of the file, the top part is just to create the test file. $hFile1 = FileOpen(@ScriptDir & "\Dummy.txt", 2) ; create dummy file, can be deleted later in the script or reused for other files FileWriteLine($hFile1, "I am line No. 1 now :P ") ; write the line to the file FileWriteLine($hFile1, " ") FileClose($hFile1) ; close the file RunWait(@ComSpec & " /c copy /b " & @ScriptDir & "\Dummy.txt + " & $sFilename & " " & @ScriptDir & "\test1.txt", "", @SW_HIDE) ; copy the dummy file to the top of the text file and create a new temp file FileMove(@ScriptDir & "\test1.txt", $sFilename, $FC_OVERWRITE) ; overwrite the original file with the temp file, deleting the temp file
    1 point
  18. As the title suggests, here are a couple of functions to append and strip @LF from a string. #cs There is StringAddCR() so I created StringAddLF() There is StringStripCR() I created StringStripLF() #ce #include <MsgBoxConstants.au3> ; Add the line feed character to all the carriage returns characters in the string. Local $sString = StringAddLF("This is a sentence " & @CR & "with " & Chr(13) & "whitespace.") ; Display the string with line feed characters added. MsgBox($MB_SYSTEMMODAL, "", $sString) ; A string with line feed characters only. $sString = "This is a sentence " & @CR & "with " & Chr(13) & "whitespace." ; Strip all line feed characters in the string. Local $sStrippedString = StringStripLF($sString) ; Display the before and after string. MsgBox($MB_SYSTEMMODAL, "", "Before: " & $sString & @CRLF & @CRLF & "After: " & $sStrippedString) Func StringAddLF($sString) ; By guinness, with the initial idea by Melba23. Return StringRegExpReplace($sString, '\r(?!\n)', @CRLF) EndFunc ;==>StringAddLF Func StringStripLF($sString) ; By guinness. Return StringRegExpReplace($sString, '\n', '') EndFunc ;==>StringStripLF
    1 point
  19. Quickstart Unzip the 2 zips (UIA*.zip and examples*.zip) of post #1 Start simplespy.au3 Hover your mouse over the element you want to handle Press ctrl+w Copy / paste the given source to a new AutoIT script If you need help ask for help in new thread in general support section and post screenshot that shows your element is highlighted with simplespy post output of simplespy with all properties attached log.txt if available in your script directory use allways contents of latest zip files which could be work in progress (WIP) zip As you will not come far if you do not understand the basics first do this Understand AutoIT http://www.autoitscript.com/autoit3/docs/tutorials/helloworld/helloworld.htm http://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm http://www.autoitscript.com/autoit3/docs/tutorials/notepad/notepad.htm Understand testing frameworks and related concepts http://en.wikipedia.org/wiki/Test_automation http://safsdev.sourceforge.net/FRAMESDataDrivenTestAutomationFrameworks.htm http://en.wikipedia.org/wiki/Keyword-driven_testing http://ewildsch.home.xs4all.nl/testautomation.htm If you understand above learn the basic way of setting focus and clicking thru UIA and the wrappers Understand IUIAutomation wrappers and framework Lets do the QuickStart steps as described above on the Start Button of Windows You will get this *** Standard code *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP0=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=Pane;class:=Shell_TrayWnd", $treescope_children) _UIA_Action($oP0,"setfocus") _UIA_setVar("Starten.mainwindow","title:=Starten;classname:=Button") _UIA_action("Starten.mainwindow","setfocus") This code is not yet perfect (and simplespy will improve over time) and you will have to change still manually _UIA_setVar is only used to get a "logical" name for a technical description There are many ways for UIA which varies from simple thru the wrappers to advanced based on the CUIAutomation2.au3 This is better coded #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP0 $oP0=_UIA_action("Title:=;controltype:=Pane;class:=Shell_TrayWnd", "getobject") _UIA_Action($oP0,"move") _UIA_action("title:=Starten;classname:=Button;controltype:=Button","move") _UIA_action("title:=Starten;classname:=Button;controltype:=Button","invoke") ;~ _UIA_action("title:=Start.*;classname:=Button;instance:=2","move") ;~ _UIA_action("title:=Start.*;classname:=Button;instance:=2","invoke") Exercise Learn first to automate some simple stuff on notepad.exe and calc.exe by starting those applications and with ctrl+w within simplespy try some code snippets See for latest examplecode the zip in first post Example 1 Iterating thru the different ways of representing the objects in the tree a. Autoit WinList function b. UIAutomation RawViewWalker c. UIAutomation ControlViewWalker d. UIAutomation ContentViewWalker e. Finding elements based on conditions (based on property id, frequently search on name or classname) ;~ Example 1 Iterating thru the different ways of representing the objects in the tree ;~ a. Autoit WinList function ;~ b. UIAutomation RawViewWalker ;~ c. UIAutomation ControlViewWalker ;~ d. UIAutomation ContentViewWalker ;~ e. Finding elements based on conditions (based on property id, frequently search on name or classname) #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> #include "CUIAutomation2.au3" #include "UIAWrappers.au3" #AutoIt3Wrapper_UseX64=Y ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os ;~ To prevent some FAQ questions consolewrite("*** Some important settings you can find in " & @scriptdir & "\UIA.CFG ***" & @CRLF) consolewrite("*** " & _UIA_getVersionInfoString() ) consolewrite("*** If logging is turned on you can find it here :" & _UIA_getVar("logFileName") & @CRLF) samplewinlist() sampleTW(1) sampleTW(2) sampleTW(3) ConsoleWrite("**** Desktop windows ****" & @CRLF) findThemAll($UIA_oDesktop, $TreeScope_Children) ConsoleWrite(@CRLF & "**** All childs of the taskbar ****") $oTaskBar = _UIA_gettaskbar() findThemAll($oTaskBar, $treescope_subtree) ConsoleWrite(@CRLF & "**** Deal with browser windows ****" & @CRLF) Local $myBrowser ;- Just get the first browser we can find $myBrowser=getBrowser() $tReturn=MsgBox($MB_SYSTEMMODAL + $MB_OKCANCEL , "Title", "Make sure you have 2 chrome browsers open otherwise press X button to abort.") if $tReturn<>$IDOK Then ConsoleWrite(@CRLF & "**** ABORTING chrome browser demo ****" & @CRLF) exit EndIf consolewrite(@CRLF & "**** Continue with finding 2 browser windows ****" & @CRLF) ;- Just get the first browser we can find of this type $browserType= "Google Chrome" ;~ $browserType= "Internet Explorer" ;~ $browserType= "Opera" $myBrowser=getBrowser($browserType,1) if isobj($myBrowser) Then consolewrite("Yes found first browser " & @CRLF) endif ConsoleWrite(@CRLF & "**** Deal with 2nd browser window****" & @CRLF) ;- Just get the 2nd browser we can find of this type $myBrowser=getBrowser($browserType,2) if isobj($myBrowser) Then consolewrite("Yes found second browser " & @CRLF) Else consolewrite("No 2nd browser found so unable to focus and highlight " & @CRLF) exit endif _UIA_Action($myBrowser,"setfocus") _UIA_Action($myBrowser,"highlight") Func sampleWinList() ConsoleWrite("sample winlist (title not empty and visible windows only)" & @CRLF) Local $hTimer = TimerInit() Local $var = WinList() For $i = 1 To $var[0][0] ; Only display visble windows If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then ConsoleWrite($i & ": Title=" & $var[$i][0] & @TAB & "Handle=" & $var[$i][1] & " Class=" & _WinAPI_GetClassName($var[$i][1]) & @CRLF) EndIf Next Local $fDiff = TimerDiff($hTimer) Consolewrite("SampleWinList took: " & $fDiff & " milliseconds" & @CRLF & @CRLF) EndFunc ;==>sampleWinList Func IsVisible($handle) If BitAND(WinGetState($handle), 2) Then Return 1 Else Return 0 EndIf EndFunc ;==>IsVisible Func getBrowser($browserName="",$browserIndex=1) local $iBrowserIdx=0 ;- Create treewalker $UIA_oUIAutomation.RawViewWalker($UIA_pTW) $oTW = ObjCreateInterface($UIA_pTW, $sIID_IUIAutomationTreeWalker, $dtagIUIAutomationTreeWalker) If IsObj($oTW) = 0 Then MsgBox(1, "UI automation treewalker failed", "UI Automation failed failed", 10) EndIf ;~ Get first element $oTW.GetFirstChildElement($UIA_oDesktop, $UIA_pUIElement) $oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) ;~ Iterate all desktopwindows While IsObj($oUIElement) = True local $tName= _UIA_getPropertyValue($oUIElement, $UIA_NamePropertyId) Local $tHandle= Hex(_UIA_getPropertyValue($oUIElement, $UIA_NativeWindowHandlePropertyId)) Local $tClassName= _UIA_getPropertyValue($oUIElement, $uia_classnamepropertyid) ;~ Browser normally put their browsername after the - (so this fails when multiple - are in title so thats why we search from right) local $tStr=stringmid($tname,stringinstr($tName,"-", $STR_NOCASESENSE, -1)+2) ;- See if its a browser (based on title it could be done on class but preferred logical name instead of a classname) ;~ Private modes diffferent title to deal with only IE misbehaves ;~ InPrivate - Internet Explorer - [InPrivate] ;~ InPrivate - [InPrivate] ?- Microsoft Edge ;~ Google Chrome (Incognito) ;~ Mozilla Firefox (Private Browsing) ;~ Privé-browsen - Opera< ;~ Fix misbehave if $tStr="[InPrivate]" then $tStr="Internet Explorer" if stringinstr($tStr," (") then $tStr=stringleft($tstr,stringinstr($tStr," (")-1) EndIf ;~ consolewrite("location: " & stringinstr($tName,"-", $STR_NOCASESENSE, -1) & "<" & $tstr & "><" & $tname & "><" & $tclassname & "><" & $tHandle & ">"& @CRLF) $itsABrowserTitle=stringinstr("Google Chrome,Internet Explorer,Mozilla Firefox,Microsoft Edge,Opera",$tStr,$STR_NOCASESENSE ) if $itsABrowserTitle > 0 then ;~ consolewrite("** Potential match ** " & $tStr & ":" & $browserName& @tab & $tname & @tab & $tclassname & @CRLF) if ($browserName=stringleft($tStr,stringlen($browsername))) or ($browserName="") Then ;~ consolewrite("** match ** " & $tStr & ":" & $browserName& @tab & $tname & @tab & $tclassname & @CRLF) $iBrowserIdx=$iBrowserIdx+1 ;~ consolewrite($browserIndex & $iBrowserIdx) if $iBrowserIDX=$browserIndex Then return $oUIElement endif EndIf EndIf $oTW.GetNextSiblingElement($oUIElement, $UIA_pUIElement) $oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) WEnd EndFunc ;==>sampleTW Func sampleTW($t) ConsoleWrite("initializing tw " & $t & @CRLF) Local $hTimer = TimerInit() Local $i=0 ;~ ' Lets show all the items of the desktop with a treewalker If $t = 1 Then $UIA_oUIAutomation.RawViewWalker($UIA_pTW) If $t = 2 Then $UIA_oUIAutomation.ControlViewWalker($UIA_pTW) If $t = 3 Then $UIA_oUIAutomation.ContentViewWalker($UIA_pTW) $oTW = ObjCreateInterface($UIA_pTW, $sIID_IUIAutomationTreeWalker, $dtagIUIAutomationTreeWalker) If IsObj($oTW) = 0 Then MsgBox(1, "UI automation treewalker failed", "UI Automation failed failed", 10) EndIf $oTW.GetFirstChildElement($UIA_oDesktop, $UIA_pUIElement) $oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) While IsObj($oUIElement) = True ConsoleWrite($i & "Title is: " & _UIA_getPropertyValue($oUIElement, $UIA_NamePropertyId) & @TAB & "Handle=" & Hex(_UIA_getPropertyValue($oUIElement, $UIA_NativeWindowHandlePropertyId)) & @TAB & "Class=" & _UIA_getPropertyValue($oUIElement, $uia_classnamepropertyid) & @CRLF) $oTW.GetNextSiblingElement($oUIElement, $UIA_pUIElement) $oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) $i=$i+1 WEnd Local $fDiff = TimerDiff($hTimer) Consolewrite("Sample tw " & $t & " took: " & $fDiff & " milliseconds" & @CRLF & @CRLF) EndFunc ;==>sampleTW Func findThemAll($oElementStart, $TreeScope) Local $hTimer = TimerInit() ;~ Get result with findall function alternative could be the treewalker Dim $pCondition, $pTrueCondition Dim $pElements, $iLength $UIA_oUIAutomation.CreateTrueCondition($pTrueCondition) $oCondition = ObjCreateInterface($pTrueCondition, $sIID_IUIAutomationCondition, $dtagIUIAutomationCondition) ;~ $oCondition1 = _AutoItObject_WrapperCreate($aCall[1], $dtagIUIAutomationCondition) ;~ Tricky to search all descendants on html objects or from desktop/root element $oElementStart.FindAll($TreeScope, $oCondition, $pElements) $oAutomationElementArray = ObjCreateInterface($pElements, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray) $oAutomationElementArray.Length($iLength) For $i = 0 To $iLength - 1; it's zero based $oAutomationElementArray.GetElement($i, $UIA_pUIElement) $oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) ConsoleWrite("Title is: " & _UIA_getPropertyValue($oUIElement, $UIA_NamePropertyId) & @TAB & "Class=" & _UIA_getPropertyValue($oUIElement, $uia_classnamepropertyid) & @CRLF) Next Local $fDiff = TimerDiff($hTimer) Consolewrite("Findthemall took: " & $fDiff & " milliseconds" & @CRLF & @CRLF) EndFunc ;==>findThemAll edit 21 aug 2014 Added quick start stuff
    1 point
×
×
  • Create New...