Sign in to follow this  
Followers 0
invis2

Using controlgettext and controlsettext

22 posts in this topic

Hope someone can help im trying to create a script to automate changing data in dialog boxes in a windows app.

Im obviously losing the plot at line 30 any help on this really appreciated.

line 29 succesfully gets me to a highlited dialog box with a number in it that i want to subtract 0.0050 from

Heres the code so far.

HotKeySet("{ESC}", "EndProg")

HotKeySet("^1","StartProg1") ;Hotkey Ctrl+1
HotKeySet("^2","StartProg2") ;Hotkey Ctrl+2

; Infinite loop
While 1
Sleep(100)  
WEnd

Func StartProg1()
    Sleep(100)
    MouseClick("left",100,200,1,0)         ;ASK BUTTON
    Sleep(100)
    Send ("{TAB 3}")
    Send ("{ENTER}")
    Send ("{TAB}")
    Send ("{ENTER}")                        ; BUY
    Sleep(5000)
    MouseClick ("right",500,500,1,0)
    Sleep(100)
    $pos = MouseGetPos()
    Sleep(100)
    MouseMove($pos[0] + 85, $pos[1] + 80, 0)    
    WinWaitActive("[CLASS:#32768]", "",2)
    MouseMove($pos[0] + 250, $pos[1] + 80, 0)
    MouseClick ("left")
    Sleep (600)
    Send ("{TAB 13}")
    $var = ControlGetText ( "Class:TcxCustomInnerTextEdit", "text", =-50 )
    Sleep(800)
    ControlSetText ( "Class:TcxCustomInnerTextEdit", "text", 1707694, "$var")
    Sleep(800)
    Send ("{TAB 6}")
    Send ("{ENTER}")
    Send ("{TAB}")  
    Send ("{ENTER}")
    
EndFunc

Share this post


Link to post
Share on other sites



invis2,

Your syntax for the ControlGetText and ControlSetText lines is not exactly correct. ;)

What does the Au3 Window Info tool tell you about the control you are trying to read? In particular, the "Title" of the window in which it situated and the "Class" and "Instance" of the control itself.

Oh, and you do not need to highlight it first! :)

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

Hi

Title: = Request Order(s)

Class: = TcxCustomInnerTextEdit

Instance: = 4

silly me yes i see i dont need to highlight now oops

Share this post


Link to post
Share on other sites

$var = ControlGetText ( "Class:TcxCustomInnerTextEdit", "text", =-50 )

you forget quotes and controlId =-50 seems wrong

ControlSetText ( "Class:TcxCustomInnerTextEdit", "text", 1707694, "$var")

and $var should be better than "$var"

may be controlId is TcxCustomInnerTextEdit4 ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

invis2,

The correct syntax needs:

- the window title (which we now have)

- some window text (which we do not need here - see below*)

- something to ID the control (which we also now have)

Try using these lines: :)

$var = ControlGetText("Request Order(s)", "", "[CLASS:TcxCustomInnerTextEdit;INSTANCE:4]")
Sleep(800)
ControlSetText("Request Order(s)", "", "[CLASS:TcxCustomInnerTextEdit;INSTANCE:4]", $var - 50)

I hope that does the trick. But some controls are resistant to this type of tampering - keep your fingers crossed! ;)

M23

* We only need to use the "text" parameter if we have to distinguish between several windows with the same title, which is often the case with dialogs.

Edit: Typnig!

Edited by Melba23

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

Here is my autoinfo for Class: TcxLabel

taken from the dialog box I wish to subtract 0.0050 from

as you can see the number in there at the moment is 1.58793

I want this number - 0.0050 ie (1.58293)

to then get put into a dialog box in another place in my program

the autoinfo for this is the next one shown Class: TcxCustomInnerTextEdit

I know im messing up here just cant get my head round it.

I think its reasonably simple what im trying to do ie select a dialog box

with a number in it subtract 0.0050 from the number and place the result in

another dialog box. Easy, well not for me it seems.

I just cant get controlgettext and controlsettext to work properly, dont get me

wrong here im sure its me , any and all help really appreciated.

>>>> Window <<<<
Title:  Request Order(s)
Class:  TReqOrdMainFm
Position:   665, 384
Size:   590, 312
Style:  0x16C80000
ExStyle:    0x00050188
Handle: 0x011E0E2A

>>>> Control <<<<
Class:  TcxLabel
Instance:   16
ClassnameNN:    TcxLabel16
Advanced (Class):   [CLASS:TcxLabel; INSTANCE:16]
ID: 6295174
Text:   1.58793
Position:   137, 77
Size:   76, 25
ControlClick Coords:    39, 13
Style:  0x56010000
ExStyle:    0x00000000
Handle: 0x00600E86

>>>> Window <<<<
Title:  Request Order(s)
Class:  TReqOrdMainFm
Position:   665, 384
Size:   590, 312
Style:  0x16C80000
ExStyle:    0x00050188
Handle: 0x00520E82

>>>> Control <<<<
Class:  TcxCustomInnerTextEdit
Instance:   4
ClassnameNN:    TcxCustomInnerTextEdit4
Advanced (Class):   [CLASS:TcxCustomInnerTextEdit; INSTANCE:4]
ID: 1577186
Text:   
Position:   185, 84
Size:   55, 13
ControlClick Coords:    43, 6
Style:  0x540100C0
ExStyle:    0x00000000
Handle: 0x001810E2

Share this post


Link to post
Share on other sites

invis2,

Ah, now we are getting to exactly what you want to do - it does help if you explain clearly to begin with. ;)

The 2 windows in the post above have different handles (0x011E0E2A and 0x00520E82), although all the other parameteres are identical. Are the label and edit actually in the same GUI and you read that data from 2 different instances? Or are they in separate windows on the screen?

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

Hi Melba23

My hands are well and truly up in the air guilty as charged, this is whatt happens when you cant sleep

and foolishly get up at 4am and convince yourself you can do some scripting before breakfast.

My first dialog box is reached by left clicking a button on screen.

My second is reached by right clicking anywhere on screen.

Number needs to be extracted from first have 0.0050 subtracted from it and inserted into second dialog box.

Really sorry about this hope you have the strength to stay with me I want to beat this if I can.

Share this post


Link to post
Share on other sites

invis2,

So we are actually dealing with controls in 2 separate dialog boxes within a main GUI. :)

I notice that the 2 dialogs have the same title - is that the same title as the main GUI? Because if so, we will need to get something to distinguish them from it. Can you please post the "class" of the main GUI if the titles are the same.

If the titles of the main GUI and the dialogs are not the same then this code should work based on the details you posted earlier: ;)

; Get to the first dialog and read the label
$var = ControlGetText("Request Order(s)", "", "[CLASS:TcxLabel; INSTANCE:16]")

; Get to the second dialog and write to the edit
ControlSetText("Request Order(s)", "", "[CLASS:TcxCustomInnerTextEdit; INSTANCE:4]", $var - .005)

If the titles of the dialogs match the main GUI we need to ID the dialogs more accurately - hopefully by class, but perhaps by location and size. ;)

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

Now that you know how to directly manipulate controls you might want to look a little closer to the rest of your script as well. Especially the Send("{TAB}") and Send("{ENTER}") parts.

I assume you use the tabs to navigate to a control you want to send the enter to. You can remove the tabs and use ControlSend(), ControlClick(), or ControlCommand() to directly manipulate the control. The usage of those commands is allot like ControlSetText().

Doing so should make the script faster and more reliable.

You might even be able to get rid of the mouseclick part in which case the application will run even when the gui is in the background, or completely hidden, meaning you can use the PC while the script is running without messing up it's progress.

Share this post


Link to post
Share on other sites

Thanks Tvern yes i see how all this can work.

i have just got to crack this bit first.

M23

I had tried almost exactly your last suggestion so im learning sort of.

then it occured to me I may not be placing the code correctly ie in right place.

So here is script as it stands.

Any thoughts.

Func StartProg1()
    Sleep(100)
    MouseClick("left",100,200,1,0)         ;ASK BUTTON
    $var = ControlGetText("Request Order(s)", "", "[CLASS:TcxLabel; INSTANCE:16]")
    Sleep(100)
    Send ("{TAB 3}")
    Send ("{ENTER}")
    Send ("{TAB}")
    Send ("{ENTER}")                        ; BUY
    Sleep(100)
    MouseClick ("right",500,500,1,0)
    Sleep(100)
    $pos = MouseGetPos()
    Sleep(100)
    MouseMove($pos[0] + 85, $pos[1] + 80, 0)    
    WinWaitActive("[CLASS:#32768]", "",2)
    MouseMove($pos[0] + 250, $pos[1] + 80, 0)
    MouseClick ("left")
    Sleep(800)
    ControlSetText("Request Order(s)", "", "[CLASS:TcxCustomInnerTextEdit; INSTANCE:4]", $var - .005)
    Sleep(800)
    Send ("{ENTER}")
    Send ("{TAB 5}")
    Send ("{ENTER}")
    Send ("{TAB}")  
    Send ("{ENTER}")
    
EndFunc

Share this post


Link to post
Share on other sites

invis2,

I presume that the code as posted does not work? ;)

It might be because the dialogs have not had time to open. If the titles of the dialogs are not the same as the main GUI (still waiting for an answer about that ;) ) try putting a WinWaitActive("Request Order(s)") before each Control* line. That way you will not try to read the control before it is actually there. :)

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

Hi M23

I must be going Ga Ga I really thought I had mentioned main Gui title, anyhow the main window has different title and class.

Im trying winwaitactive and will let you know .

Thanks

Share this post


Link to post
Share on other sites

Still having trouble im afraid

I include the script in its present form

any thoughts ?

the script completes about 10 lines culminating in a succesful action but as soon as we want info ie ControlGetText

It seems to get lost.

Func StartProg1()
    Sleep(100)
    MouseClick("left",100,200,1,0)         ;ASK BUTTON
    WinWaitActive ("Request Order(s)", "",2)
    $var = ControlGetText("Request Order(s)", "", "[CLASS:TcxLabel; INSTANCE:16]")
    Sleep(100)
    Send ("{TAB 3}")
    Send ("{ENTER}")
    Send ("{TAB}")
    Send ("{ENTER}")                        ; BUY
    Sleep(800)
    MouseClick ("right",500,500,1,0)
    Sleep(100)
    $pos = MouseGetPos()
    Sleep(800)
    MouseMove($pos[0] + 85, $pos[1] + 80, 0)    
    WinWaitActive("[CLASS:#32768]", "",2)
    MouseMove($pos[0] + 250, $pos[1] + 80, 0)
    MouseClick ("left")
    Sleep(800)
    WinWaitActive ("Request Order(s)", "",2)
    ControlSetText("Request Order(s)", "", "[CLASS:TcxCustomInnerTextEdit; INSTANCE:4]", $var - .005)
    Sleep(800)
    Send ("{ENTER}")
    Send ("{TAB 5}")
    Send ("{ENTER}")
    Send ("{TAB}")  
    Send ("{ENTER}")
    
EndFunc

Share this post


Link to post
Share on other sites

invis2,

Annoying! ;)

Add this to the top of your script:

Opt("TrayIconDebug", 1)

and run it. When it appears to hang, put your cursor over the tray icon and see what line we are on. :)

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

Thats a great little debugger

I found a small error which i fixed where mouse movement was concerned and corrected that

the script runs through from my perspective but doesnt succeed in changing the number.

I put 5 second waits between just about every command with the debugger in place and the script

runs completely through and back to line 10 as far as i can tell.

The problem seems to be in controlgettext or controlsettext.

I cant tell if any of that part of the script worked , is there a simple way of printing to screen

the number found by controlgettext, im just thinking this might allow us to see which bit isnt responding.

My 2 cents ....... Any thoughts

Thank you very much by the way for all your help so far.

Share this post


Link to post
Share on other sites

is there a simple way of printing to screen

If you are running from SciTE you can use:

ConsoleWrite("The value of $var is " & $var & @CRLF)

Otherwise I ToolTip("The value of $var is " & $var & @CRLF) will do the trick.

Just add it after ControlGetText

Share this post


Link to post
Share on other sites

Hi Again

Well some progress of sorts.

I can proficiently use ControlGetText and ControlSetText as I have changed figures at least momentarily

to the desired number only to see them revert to the origional sum all by itself.

I have used this set of controls to alter other dialog boxes on the same screen and they all react the same (they revert to the origonal)

I have tried mousemovements to the dialog box with 1 and 2 clicks I have tried tabbing to the box concerned and

sent enter command and nothing prevents the number change from reverting.

No prizes for the next question .

Any thoughts how I can make the number I have succesfully altered , stay altered.

Any tricks thoughts help or magic gratefully recieved ...... Oh and script of course ;)

Share this post


Link to post
Share on other sites

@invis2

Send ("{ENTER}") ; BUY

If this is some kind of buying/selling software you're running,

it would be very surprising if it didn't (try to) keep you from

manipulating it ...

whim

Share this post


Link to post
Share on other sites

It is buying selling software but I see no reason for it to stop me automating etc

but you may well be right this could be the problem.

Does anyone know any possible techniques for proving this situation.?

Or indeed solving the issue.

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