Sign in to follow this  
Followers 0
jack71

Need help with a simple script (ControlClick issues)

26 posts in this topic

#1 ·  Posted (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 by jack71

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by l3ill

Share this post


Link to post
Share on other sites

....

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 Gude
How 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

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by l3ill

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

Opt("WinTitleMatchMode", 2)
WinActivate ("Acquisition", "")
Local $window = WinGetTitle("[ACTIVE]")
ControlClick($window, "", "[ClassnameNN:Button61]", "Left", 1)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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
WEnd
M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Not according to my help file :P

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 by l3ill

Share this post


Link to post
Share on other sites

l3ill,

 

Not according to my help file

Read more carefully - click on the link in the mode 4 line and you read:

 

"Mode 4 (Kept for backward compatibility)

Advanced mode

Must 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#17 ·  Posted (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!  :rolleyes:

Edited by l3ill

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0