jack71 Posted January 9, 2014 Share Posted January 9, 2014 (edited) I'm new to autoit and kind of rusty on scripting. I'm trying to write a simple script that will 'Left click' on a button in a program I'm using, to help automate the downloading of data. Here's what I written: Download() Func Download() Local $hWnd = WinGetHandle("Acquisition", "") WinActivate($hWnd) ControlClick("$hWnd", "", "Button61", "Left") EndFunc I want it to make the window with the partial title "Acquisition" the active window. Then left click the stop button, which with the autoit finder is ClassnameNN Button61. This script does nothing :/. Thanks in advance. Edited January 10, 2014 by jack71 Link to comment Share on other sites More sharing options...
l3ill Posted January 9, 2014 Share Posted January 9, 2014 (edited) Hi jack71, and welcome to the forum !! take the quotes from around the vaiable in ControlClick and attempt to use the classname - may need some optimizing. trolClick($hWnd, "", "[ClassnameNN:Button61]", "Left") Edited January 9, 2014 by l3ill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Malkey Posted January 9, 2014 Share Posted January 9, 2014 ....I want it to make the window with the partial title "Acquisition" the active window. ... You need to use:- Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase I believe either "[ClassnameNN:Button61]" or "Button61" may be used in the "controlID" parameter of the ControlClick function. Link to comment Share on other sites More sharing options...
jack71 Posted January 10, 2014 Author Share Posted January 10, 2014 Thanks for the tips guys, however I'm still not getting it to work. Here's what I have now: local $window Opt("WinTitleMatchMode", 2) WinActivate ("Acquisition", "") WinGetTitle("[ACTIVE]") = $window ControlClick("$window", "", "[CLASS:Button; INSTANCE:61]", "Left") What this does for me is brings up the window with the string "Acquisition" to the front, but it doesn't make it active for some reason which is why I'm guessing it doesn't click the button. I tried adding the line "WinWaitActive("$window", "") before the controlclick function but it doesn't work either and just sits there, then I have to ctrl-brk to stop the script. Any ideas what I'm doing wrong? Thanks. Link to comment Share on other sites More sharing options...
jack71 Posted January 10, 2014 Author Share Posted January 10, 2014 Alright did a little more reading and tried this code: Opt("WinTitleMatchMode", 2) WinActivate ("Acquisition", "") Local $window = WinGetTitle("[ACTIVE]") ControlClick("$window", "", "[CLASS:Button; INSTANCE:61]", "Left", 1) Still the same issue. Link to comment Share on other sites More sharing options...
BrewManNH Posted January 10, 2014 Share Posted January 10, 2014 Remove the quotes from around $window in the ControlClick function, and try it again. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
l3ill Posted January 10, 2014 Share Posted January 10, 2014 (edited) That & you said in your first post that the button info was "[ClassnameNN:Button61]" The it should look something like this: Opt("WinTitleMatchMode", 2) WinActivate ("Acquisition", "") Local $window = WinGetTitle("[ACTIVE]") ;ControlClick("$window", "", "[CLASS:Button; INSTANCE:61]", "Left", 1) ; That ^ & This ^ ControlClick($window, "", "[ClassnameNN:Button61]", "Left", 1) Edited January 10, 2014 by l3ill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
jdelaney Posted January 10, 2014 Share Posted January 10, 2014 (edited) There are much better ways than instance based. Instance based may break due to user security (in some apps) or new buttons being added. Use the ID instead. those are generally unique and stale. Edited January 10, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
jack71 Posted January 11, 2014 Author Share Posted January 11, 2014 Thanks again everyone for your input but I still can't get it to click :/. Here's the summary from the Autoitinfo tool, maybe I'm missing something...: >>>> Window <<<< Title: Acquisition John Doe 1/11/2014 Volume No.:HD Class: Afx:00400000:b:00010011:00000006:002104DD Position: -4, -4 Size: 1288, 1002 Style: 0x15CFC000 ExStyle: 0x00000100 Handle: 0x00040658 >>>> Control <<<< Class: Button Instance: 61 ClassnameNN: Button61 Name: Advanced (Class): [CLASS:Button; INSTANCE:61] ID: 11301 Text: Start Position: 1052, 22 Size: 88, 41 ControlClick Coords: 74, 26 Style: 0x50010000 ExStyle: 0x00000004 Handle: 0x000207A4 >>>> Mouse <<<< Position: 1126, 94 Cursor ID: 0 Color: 0xF3F3EE Link to comment Share on other sites More sharing options...
l3ill Posted January 11, 2014 Share Posted January 11, 2014 Hi again, post your code, sometimes its a little syntax doodle...(like quoting a variable) My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
jack71 Posted January 11, 2014 Author Share Posted January 11, 2014 Opt("WinTitleMatchMode", 2) WinActivate ("Acquisition", "") Local $window = WinGetTitle("[ACTIVE]") ControlClick($window, "", "[ClassnameNN:Button61]", "Left", 1) Link to comment Share on other sites More sharing options...
jack71 Posted January 11, 2014 Author Share Posted January 11, 2014 Alright I definitely think it's a syntax issue, According to the helpfile: ControlClick ( "title", "text", controlID [, button = "left" [, clicks = 1 [, x [, y]]]] ) I can't figure out the correct syntax when you get past the ControlID part. ControlClick ($window, "", 11301 [, button="left" [, clicks =1]]) throws an invalid syntax in the script editor. Link to comment Share on other sites More sharing options...
l3ill Posted January 11, 2014 Share Posted January 11, 2014 For one thing the WinTitleMatchMode should be set to 4 if you want the WinGetTitle("[ACTIVE]") to work. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 11, 2014 Moderators Share Posted January 11, 2014 l3ill,Not so - it works fine in the default mode (1); #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test GUI", 500, 500) $cLabel = GUICtrlCreateLabel("", 10, 10, 200, 20) GUISetState() Sleep(1000) GUICtrlSetData($cLabel, WinGetTitle("[ACTIVE]")) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
l3ill Posted January 11, 2014 Share Posted January 11, 2014 (edited) Not according to my help file Okay but 2 would definitely not work. correct? jack71 Try this: I don't have your program so I had to use Notepad, this works so maybe it will help you figure yours out: Opt("WinTitleMatchMode") ShellExecute("notepad") Sleep(2000) ; added for testing $window = WinGetTitle("[ACTIVE]") ConsoleWrite("$window = " & $window & @CRLF) ; added for testing see in the console which program shows up ControlClick($window, "", "", "Right", 1) ;ControlClick($window, "", "[ClassnameNN:Button61]", "Left", 1) ; removed for testing Edited January 11, 2014 by l3ill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 11, 2014 Moderators Share Posted January 11, 2014 l3ill, Not according to my help fileRead more carefully - click on the link in the mode 4 line and you read: "Mode 4 (Kept for backward compatibility)Advanced modeMust be replaced with Advanced Window Descriptions which does not need any mode to be set."So as the example demonstrated the advanced window descriptions will work with any mode. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
l3ill Posted January 11, 2014 Share Posted January 11, 2014 (edited) Sure now I get it, but when answering his question I looked here: WinTitleMatchMode Alters the method that is used to match window titles during search operations. 1 = (default) Match the title from the start 2 = Match any substring in the title 3 = Exact title match 4 = Advanced mode, see Window Titles & Text (Advanced) -1 to -4 = Case insensitive match according to the other type of match. and it seems as though the advanced modes will only work with Mode 4 since that is where the link is located... then you click on the link and see - Mode 1 (Matches partial titles from the start.) Not very clear at first glance... So 4 is only left there so older scripts wont break and 1 is the new Jack of all trades. Thanks for clearing that up! Edited January 11, 2014 by l3ill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 11, 2014 Moderators Share Posted January 11, 2014 l3ill, Not very clear at first glance...Agreed - I will look at rewriting that bit. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jdelaney Posted January 11, 2014 Share Posted January 11, 2014 Use the ID instead ControlClick($window, "", 11301) IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 11, 2014 Moderators Share Posted January 11, 2014 l3ill,I have amended the text in both the Opt and Advanced Window Title Help file pages to clarify the fact that the Advanced Window Descriptions work in all modes. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now