Jump to content
Sign in to follow this  

ControlSend errors

Recommended Posts


I am having a seemingly rare issue where control send sends the wrong string to a GUI

String to send:       AA-111BB-CC-DD

Sometimes I get:   AA-111BB_CC-DD

or a variant of some sorts where it looks as if the Shift key carries over for 1 character.

I have browsed the forums looking for an answer, but I didn't see anything in particular that would help.



Share this post

Link to post
Share on other sites

Here is the bit that has been giving me trouble. I am attempting to automate a program that is not friendly to automation to begin with, but it is working for the most part...until I came to this.

It is also referencing some external information, but a lot of that is work related and can't be given out sorry!

hopefully this is enough?

Essentially the goal of this part is to search and create parts if that are not there. While entering the information into the fields I get the above mentioned error.


    For $R=0 To ($AFFIX[0]*$AFFIX[1]) Step 1
        $LISTNUM=ControlListView("WINDOW1","", _
        "[CLASS:ListView20WndClass; INSTANCE:1]","GetItemCount")
        For $O=1 To $LISTNUM
        For $S=1 To $LISTNUM
            ControlClick("WINDOW1","","[CLASS:AfxOleControl42; INSTANCE:2]","Left",4)
            $MSTR_CHCK[$LOCATION][1] = 1
    $MSTR_SRCH[$R][1] = 1
    ControlClick("WINDOW1","","[CLASS:AfxOleControl42s; INSTANCE:3]","Left",2)
    ControlSend("Search","","[CLASS:AfxOleControl42; INSTANCE:1]",$USER_LIGHT&"-"&$MSTR_SRCH[($R+1)][0])
    ControlClick("Search","","[CLASS:AfxOleControl42s; INSTANCE:1]","Left",2)
    If $WINVAR<>0 Then
        ControlClick("[CLASS:#32770]","","[CLASS:Button; INSTANCE:1]","Left",2)
        ControlClick("WINDOW1","","[CLASS:AfxOleControl42s; INSTANCE:2]","Left",2)
        ControlClick("WINDOW2","","[CLASS:AfxOleControl42; INSTANCE:3]","Left",4)
        ControlSend("WINDOW2","","[CLASS:AfxOleControl42; INSTANCE:3]","{BACKSPACE}")
        ControlSend("WINDOW2","","[CLASS:AfxOleControl42; INSTANCE:3]",$USER_LIGHT& _
        ControlClick("WINDOW2","","[CLASS:AfxOleControl42; INSTANCE:2]","Left",4)
        ControlSend("WINDOW2","","[CLASS:AfxOleControl42; INSTANCE:2]","{BACKSPACE}")
        ControlSend("WINDOW2","","[CLASS:AfxOleControl42; INSTANCE:2]",$USER_LIGHT& _
        ControlClick("WINDOW2","","[CLASS:AfxOleControl42s; INSTANCE:3]","Left",2)
        WinWait("Verify Copy","")
        ControlClick("Verify Copy","","[CLASS:Button; INSTANCE:1]","Left",2)

Edit: I am sure this is messy and there is a better way too! Feel free to comment on anything else too!

Edited by randominetdude

Share this post

Link to post
Share on other sites

Huh, I had no idea about ControlSetText command. I will give this a go and see if it works like I need it to, because I believe the program I am using just doesn't like keystrokes sent to it. Many of my past issue with said program have involved me finding round about ways to get it to receive keystrokes before.

I will report back again!

Thanks a lot Bert!

Share this post

Link to post
Share on other sites

Hmm, unfortunately this didn't work. The control doesn't accept that as a valid entry. Sorry -- this issue could honestly just be the program itself being problematic.

Is there a method to have all key presses not be help at all and it just send the characters? If I can do that I could just turn caps lock on and have it send that way right?

Not sure here, but any advice would be nice, thanks for all of your help so far!

Share this post

Link to post
Share on other sites

I can tell you I've seen this problem for years and the only work around I've found when it resist ControlSetText is to do a control read after I sent the text to the control and then do a string match between what is returned and what I intended the control to have. If the string does not match I will resend to the control again and verify. It is messy but it works.

1. COntrolsend

2. Read the control I just sent data to

3. compare the data from the "read" to what I want the data to be.

If they do not match, go back to step 1 and try again.

If they match, then the control has the correct data.

Edited by Bert

Share this post

Link to post
Share on other sites

So I explored a bit more, since the program I am automating resists Bert's method, I tried something else and changed a few options. The accuracy in the program is ~99% (99.59%)  now with my latest tests,  with zero control send errors(that I have seen).

I changed the following Options:


The above options solved it for me, unless this doesn't do a whole lot.

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  

  • Create New...