Jump to content

etidd

Active Members
  • Posts

    32
  • Joined

  • Last visited

Everything posted by etidd

  1. Oops, I found all relevant files in the other thread called "UI Automation UDF's". Sorry about that. Now, the example code has been put into a script that I temporarily named UIAExample.au3 which just runs and performs nothing - no clicks to the maximize button in Winamp. Occasionally, I can see additional elements in UIA Spy after pressing F3 over the maximize button, but most of the time, I get nothing and have no idea what that control is called or what its ID number is. This must be the problem. Maybe I can do a ConsoleRead() to get the data output from the example code as that might provide insight into what the issue is. I'm starting to doubt that UIA objects will work for Winamp. I should follow up this post with an example code for Nitro PDF which has clearly identified UIA elements. I'll try my best. Maybe I'll even get it right! Thanks very much. -ty
  2. junkew, Pardon me if I have made you repeat certain points you've already covered in your FAQ section. I'm doing my best to keep up. Although, I have another canned FAQ to ask before I can even address troubleshooting this example you carefully put together. I looked through the Includes folder several times and cannot find these files: UIA_Functions.au3, UIA_SafeArray.au3, and UIA_Variant.au3. None of these files are in the folder called "GuiIncludes" in the UIASpy.7z archive as it states in the code comments. Obviously, the compiler throws an error about missing files and doesn't execute the example code above. I'm browsing the linked threads above and am still looking for a download that contains these file dependencies. I have UIAWrappers.au3. Next, you wrote this about Winamp's tree of controls: In Winamp, I pressed F1 through F4 while the mouse was hovering over the maximize / restore button (since that is the desired control to be targeted for a mouse click) with UIA Spy simultaneously running. In UIA Spy, Winamp does indeed have very few recognized controls (2 panes). A third pane appears called "BaseWindow_RootWnd" after I press F4, but there are no relevant controls in that pane. It is empty. After pressing F4 over the file pane, UIA Spy did uncover a ton of elements; however, none of them were the maximize button. Here is what I'm seeing below: The main pane is the 2nd one. "WinampVis" is almost certainly the Winamp Visualization tab that can be clicked from within the main window. So, I don't know how to reproduce your method of pressing F1-F4 to expose the title bar controls for Winamp. This seems more difficult to do Winamp first whereas the tabs in Nitro PDF are discovered by UIA Spy without any keyboard trick. I haven't gotten to the point of running the example code you wrote to examine why it's not actually performing the click. My solution using WinGetPos() works as long as the non-maximized window is within the viewport. If the window is dragged off the screen to the right, it will not work. I was brainstorming a solution to perform a mouse click and drag on the title bar and position the window in the middle of the screen and then do the click on the maximize button. I also should find out how to determine whether an application is 32 or 64 bits. I'm going to study the examples to grow my understanding while I work toward solving challenging cases like Winamp.
  3. I found an example on another one of your posts: #include "CUIAutomation2.au3" #include "UIAWrappers.au3" ;- 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 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) ; this could be adjusted to one line calling for $UIA_BoundingRectanglePropertyId, right? 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 I don't know what dependencies there are for this code to run RawViewWalker(). I'll keep reading your example work.
  4. Is this the appropriate page? Custom drawn TreeViews and ListViews You said "treewalker".
  5. I'm approaching the strategy of manipulating controls better. However, the approach must be different in the original case that I posted about above regarding clicking the PDF tabs. In a creative approach, I checked to make sure I had enabled all available keyboard shortcuts. I can also set bookmarks, but it still requires automation to initiate the bookmark controls. I want things set at a proper zoom as well so I can see important documents. I did find a command of CTRL + W which will close the documents in my shut down script. ControlViewer.au3 can only see and identify the main workspace pane within Nitro PDF, but UIA Spy can see the direct details inside of all PDF tabs and several various controls. I see $UIA_BoundingRectanglePropertyId has values of l=237,t=147,w=107,h=21. So, do I have to make a UIA object to retrieve these 4 values for this control? Why can't I just get those values and subtract 35 from the x value in MouseClick() and be happy? Even just being able to check the existence of the tabs as open documents as a Boolean / conditional expression will help immensely in designing this code for different cases in startup.
  6. Truly brilliant, rsn. I'm so glad I presented this case study of Winamp 5.9.2. I have at least 2 or 3 other controls, including Windows controls in file Explorer, that I want to target in my next posts. It's all about creativity in manipulating various elements and controls in applications you are trying to automate using AutoIt. Yes, the above code snippet you posted does the task of maximizing the Winamp window, but as you said, the window doesn't align properly at coordinates 0,0. For some reason, suppose the GUI is developed in a language that isn't fully compatible with Win7 (you can't inspect any elements using any spy tool.), it is positioned in an odd way as such: You can do rsn's code above as many times as you like as long as Winamp is restarted once per script run, but I came up with something a little bit more simple using WinGetPos() and an arithmetic expression inside of a MouseClick() function: If Not ProcessExists("winamp.exe") Then Run("C:\Program Files (x86)\Winamp\winamp.exe") WinWaitActive("Winamp 5.9.2 Build 10042") ; a special algorithm to maximize the Winamp window If WinGetState("[ACTIVE]","") <> @SW_MAXIMIZE Then Local $winampSize = WinGetPos("[ACTIVE]") ; TEMP DEBUGGING ;MsgBox(0, "Winamp Window Size & Coordinates", "X coordinate: " & $winampSize[0] & @CRLF & "Y coordinate: " & $winampSize[1] & @CRLF & "Width: " & $winampSize[2] & @CRLF & "Height: " & $winampSize[3]) ;MsgBox(0, "Click Location", "X coordinate: " & $winampSize[2] + $winampSize[0] - 55 & @CRLF & "Y coordinate: " & $winampSize[1] + 6) MouseClick($MOUSE_CLICK_LEFT, $winampSize[2] + $winampSize[0] - 55, $winampSize[1] + 6) ; add the width and the x-coordinate and subtract 55 and add 6 to the y-coordinate to target the maximize button EndIf Sleep(400) ; adding sleep here allows Winamp to load before the script tries to navigate the menu. MouseClick($MOUSE_CLICK_LEFT, 477, 323) ; have to click the artist pane because keyboard functions dont work after the window bar has been clicked Sleep(400) Send("m" & "a") Send("{DOWN 30}") Send("{UP 2}") Sleep(800) ConsoleWrite("+++ Script opened Winamp successfully. +++" & @CRLF) Else ConsoleWrite("*** Winamp is already running. ***" & @CRLF) EndIf It works all over the screen wherever the Winamp window may be. I think it will have to do quite right! 50 points for the Monkeyboy Of course, this is all dependent upon the screen resolution being 1920 x 1080 pixels. I will have to continue my work on a preliminary script that checks the desktop resolution and internet connection beforehand.
  7. Here's yet another case of targeting unfamiliar controls for mouse clicks. See Winamp screenshot below with pointer over the maximize window button; I need to click that button (or invoke it or give focus to it) as a part of my PC startup script. What would be an appropriate way of targeting its position and sending a click to its position as discovered beforehand by the script (and stored into a variable if necessary)? As you know very well, there can be no static position (whereas the coordinates are the same every time) because the window may be in a different position. This example is even more more tricky because there are no UIA elements, and there is no keyboard shortcut as set forth by the software engineers. I doubt the software is open-source and going directly through the Winamp software code would yield a sensible solution. Also, the following code will not work successfully as it does with several other programs: If WinGetState("[ACTIVE]","") <> @SW_MAXIMIZE Then WinSetState("[ACTIVE]","",@SW_MAXIMIZE) EndIf I actually have an idea of what I might do to target the position of the Winamp maximize window button. I think I can use WinMove() first and then obtain the window size and yield a suitable coordinate combination by performing subtraction between the window dimensions and the screen resolution. As you said, some AI development could become the hybrid solution that enables the script to make basic determinations about window buttons, etc. across different GUI's; however, I'm not surprised that clicking (in general) would be the major roadblock I encounter when starting my journey toward PC automation / workspace optimization.
  8. Hi LKP and junkew, Thanks very much for your responses. We all commend junkew for his brilliant code work on the useful UIA Spy tool and other contributions. I should have responded sooner as I have been reading threads like this one. In that thread, you had a similar discussion. It was mentioned that an .Invoke() function had been written and included in the UIA code. This page discusses the Invoke Control Pattern and goes on to mention that an automation element is invoked by clicking or double-clicking it. I found where unavailable properties could be displayed in UIA Spy ("Right Pane" --> "Show default and unavailable properties"), and I found this information: $UIA_IsInvokePatternAvailablePropertyId False (InvokePattern) Your comments seem to amount to say that a click on a desired "TabItem" control cannot be performed with UI Automation in this case. So, is it possible to extract the bounding rectangle dimensions and/or coordinates of controls available within the UIA properties and store the values into variables and perform a mouse click at appropriate coordinates? As mentioned in your above-linked thread, this is resolution dependent (thus is why I check the screen resolution before the script starts). All I want to do is to be able to retrieve the control's coordinates and simply click it at this point. I don't know what a sendmessage or Keybd event is or what sendinput is. Is that in your program? If I know what these events are and how to invoke them as functions in the code, this may be the solution to manipulate these seemingly foreign, incompatible controls. This is a standard desktop without any touchscreen functionality. Hopefully, that's a baseline for compatibility with this sort of programming for automation in Windows. I seem to encounter this issue of clicking controls most frequently in my journey of learning AutoIt. I'm not even able to click files or links / libraries inside of Windows Explorer (shown as "ListItems" in UIA Spy)! After processing your comment about looking for a solution for 30 years, it sounds like I need to be less choosy and utilize most working solutions.
  9. Hi, argumentum. At startup, I want to load documents into the PDF software, click the PDF tabs, and navigate to certain places in the documents (perhaps there is a tool for bookmarking). I prefer this software over Adobe Acrobat Reader. I mentioned that I have encountered difficulty when clicking page elements by control ID or other property. See this bit of code: ControlClick("---image window name---", "", "[CLASS:Photos_ButtonEx; ID:42006; INSTANCE:10]", $MOUSE_CLICK_LEFT) It, too, fails to click a Windows control in Windows Photo Viewer (the zoom scroller). Have you experienced a situation in which you had difficulty clicking something using AutoIt? This is about implementing UIAutomation in AutoIt like this thread: Using UI Automation Code in AutoIt
  10. Hi everyone, As I have made progress as a novice in AutoIt, I have always noticed clicking various items without relying on coordinates or keystrokes has been the most tricky limitation. I have been studying UI Automation elements and how to manipulate them using AutoIt by reading several different forum posts after noticing I was unsuccessful in clicking Windows controls with ControlClick(). For this particular post, I'm trying to learn how to click tabs in a non-windows GUI (a PDF editor). Using LarsJ's UIASpy.au3, I am able to discover the tabs by UIA element and ID number. I want to be able to click through the tabs one-by-one and change the navigate the documents using the software's page number control at the bottom of the GUI. Here is what the PDF viewer tabs look like: (software application is called Nitro Pro PDF 10) Here is the UI Automation property reference from UIA Spy: Its ID number is 12704 according to the following property sheet in UIA Spy: Here is the sample code generated by the UIA Spy application: ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) #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 "UIA_Constants.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation ) 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, $dtag_IUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) EndFunc I have not executed this code, but I see nothing there that would initiate a click on a UIA element by specified ID or other property identifier. Here are some other times when I've experienced trouble clicking Windows controls by ID or class: clicking the zoom button on Windows Photo Viewer clicking buttons for options menus clicking items in the Control Panel The quick fix in most cases is to send keystrokes or keystroke combinations as a bypass of the mouse pointer. Is it possible to read coordinates and store them into variables and then send a click to the coordinates? What are the cases that no clicks can be sent to a control in a GUI (if any)? This would be a great discussion for me on a milestone issue. Thanks very much in advance for any/all responses. I'm making good progress.
  11. Here's the sample code from UIASpy. Can anything be done with this? ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "11", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pListItem1, $oListItem1 $oParent.FindFirst( $TreeScope_Descendants, $pCondition0, $pListItem1 ) $oListItem1 = ObjCreateInterface( $pListItem1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oListItem1 ) Then Return ConsoleWrite( "$oListItem1 ERR" & @CRLF ) ConsoleWrite( "$oListItem1 OK" & @CRLF ) $oParent is undefined here.
  12. I downloaded a previous version of AU3Info that doesn't crash. Still, the control information is the same. This command works, but it doesn't target the desired control (a specific file in the window): ControlClick("Music", "", "[CLASS:DirectUIHWND; INSTANCE:3]", $MOUSE_CLICK_LEFT) That control appears to be the most specific AutoIt can target in file explorer. It cannot target specific files. I did some reading in previous threads here. I think what I'm stating is correct that specific files cannot be targeted for clicks by AU3 pre-defined functions. Now, I will try to learn about .Invoke() and .Select() using the UIA properties. Do you have a sample on how either of these functions are used? This whole errand may not be worthwhile. I can click within the desired region. Then, I can just send some down arrow keystrokes.
  13. So, I had a new idea to create a UDF that checks the current screen resolution and window sizes to ensure that the script will properly execute as tested. Maybe I would put it in a separate .au3 file and include it with most scripts. This is similar to what I am doing by checking if certain processes are running and closing them before executing a script as if a program is currently running, it may cause a problem in execution. Perhaps this has already been done before as it seems like it may be a sound practice. If a window size is different than when it was tested, it may cause the script to malfunction. Does anyone do things like this or calculate coordinates by function? Or is this overblown and just better to target everything with precise coordinates?
  14. Hello to all my friends that live inside of my computer! I'm still having trouble getting a click sent to a specific control. In this case, it is a file inside of a file explorer pane. I'm assuming I can target actual files and just about anything that comes up in UIASpy or Control Viewer. I can easily achieve the click I want with MouseClick() with accurate coordinates, but I think it is best to avoid specific coordinates should the screen resolution or window size be different at runtime. I tried using ControlClick() with the following parameters: WinWait("Music") WinMove("[ACTIVE]", "", 999, 320) MouseWheel($MOUSE_WHEEL_DOWN, 10) ; scrolling down to the bottom of the window so the target file is in view **Working** Sleep(2000) ControlClick("Music", "", 11, "left") ; not working! ControlClick("Music", "", "[ID:11]", "left") ; not working! ControlClick("Music", "", 31812, "left") ; not working! ControlClick("Music", "", "[ID:31812]", "left") ; not working! I gave it 2 seconds to allow for timing. I also tried using the constant $MOUSE_CLICK_LEFT. Here is the control information that I found on the target in UIASpy. Still having trouble finding out how to use ControlClick(). Any thoughts?
  15. Thanks to all for the informative replies. I started by sending ALT+D to the explorer windows on XMan's suggestion, but I switched to the use of Shell COM objects per AllenAA's input. This is what part of the script looks like: ; creation of shell COM object Local $oShell, $oShellWindows, $oShellWindow $oShell = ObjCreate("Shell.Application") $oShellWindows = $oShell.Windows If $oShellWindows.Count = 0 Then MsgBox($MB_ICONWARNING + $MB_TOPMOST, "Warning", "No Explorer windows found.") ; second round of backup $oShellWindow = $oShellWindows.Item($oShellWindows.Count - 1) ; selects the window I want $oShellWindow.Navigate("----folder location redacted----") ; goes to the new destination Sleep(500) WinActivate("Default") Sleep(500) Send("^a") Send("^c") $oShellWindow = $oShellWindows.Item($oShellWindows.Count - 3) ; selects the other window I want $oShellWindow.Navigate("----other folder location redacted----") ; goes to the new destination Sleep(500) WinActivate("Chrome Data") Sleep(500) Send("^v") Sleep(3000) I'm surprised by how important timing is in AutoIt. After employing the Shell COM objects and making sure the Sleep() commands were consistent, the timing issues were resolved, but timing is likely to be the topic of a future thread of mine or a topic I need to read further on as I become more proficient in this language. Now, I have a working script! (although, I want to add a thing or two more in there to make it even better and more reflexive if it is run under different conditions) I downloaded UIASpy.au3 by tankew, but I have just downloaded Control Viewer on your recommendation so I have that as well. I have begun to use UIASpy to pinpoint control ID's and learn more about targets I can manipulate in a future script. ---- I'm really impressed by all that was put together by the AutoIt developers. This is a really cool language.
  16. Hi all, 👋 I want to navigate to another folder in Windows Explorer, but it seems there is no predefined function to do this. Here is a link to another thread on this topic. Unfortunately, the code snippet below does not achieve this: If WinActive("User Data") Then ControlClick("User Data", "", 1001, "left", 1) Send("C:\Users\Tyler\AppData\Local\Google\Chrome\User Data\Default" & "{ENTER}") EndIf Of course, 1001 is not a valid Control ID. I wish I could use the AutoIt Window Info Tool to check the different controls in the window, but it crashes every time I run it. Is there another way to do this in the same explorer window, or am I going to have to resort to opening a new window? Thanks in advance.
  17. Both benners and ioa747 supplied working examples, though I'm still deciphering this line: _WinAPI_ShellFileOperation($s_Dir, '', $FO_DELETE, BitOR($FOF_ALLOWUNDO, $FOF_NO_UI)) Particularly, I'm learning about what a bitwise operator is. --- As for emptying the recycle bin, I'm having an issue with the FileRecycleEmpty() function. It does not work with these rootpaths: FileRecycleEmpty(@HomeDrive) FileRecycleEmpty("C:\") It only seems to perform when it is simply FileRecycleEmpty(). Perhaps, I didn't give it long enough, though I waited for over a minute.
  18. Trong, I created a new .au3 file in the Include folder and used the _EmptyDir() function without success. Assuming you wrote that code, it is very intriguing but beyond my level of comprehension as I have just started to learn AutoIt. I would be interested in breaking down some of those lines with comments. I referenced the @ComSpec macro to learn what that is.
  19. The foregoing snippets are deleting the whole directory but only after human intervention. As soon as I interact with the files to do what I desire them to do, the directory disappears by action of the script.
  20. The following commands aren't deleting the contents of a folder and its sub-directories: DirRemove("E:\Internet Browser Data\Brave Data", 1) Sleep(5000) DirRemove("E:\Internet Browser Data\Brave Data") Sleep(5000) I found this script on another website, but I think it is much more simple than the following script: $search = FileFindFirstFile("*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error <> 0 Then ExitLoop If $file = "keep me" Then ContinueLoop If $file = "." Or $file = ".." Then ContinueLoop If StringInStr(FileGetAttrib(@SCRIPTDIR & "\" & $file) , "D") Then DirRemove($file, 1) Else FileDelete(@SCRIPTDIR & "\" & $file) EndIf WEnd FileClose($search) The objective here is to remove the old contents of a folder and replace them with updated files. I prefer to leave the parent folder in tact without deletion.
  21. Ah, I figured this had to do with timing. I'm running quite a few processes on the PC as well. You're a genius.
  22. Nope, that didn't do anything this time. Reading up on the options I can change using AutoItSetOption().
  23. So, when I target an explorer window by title, the WinMove() function will not execute: Run("explorer.exe \n, E:\Internet Browser Data\Brave Data") WinMove("Brave Data", "", 464, 383) Run("explorer.exe \n, E:\Internet Browser Data\Brave Data") WinMove("[TITLE:Brave Data]", "", 464, 383) If I target the window as [ACTIVE], it will move the previously opened Explorer window. I wonder if that has to do with computer memory since I'm running a lot of programs. The AutoIt Window Info tool is crashing when I try to find out more. I'm stumped again.
  24. Yes, this is perfect. Blessings.
  25. I looked at the properties tab again. I suppose they are called shortcuts. Desktop.lnk
×
×
  • Create New...