Jump to content

ControlSend errors


Recommended Posts

Hello!

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.

Thanks!

 

Link to comment
Share on other sites

  • Moderators

How about posting your code, so we can see what you're doing? It may just be that you need to set the flag parameter to send keys as Raw.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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.

If $AFFIXNUM=3 Then

    For $R=0 To ($AFFIX[0]*$AFFIX[1]) Step 1
        $LISTNUM=ControlListView("WINDOW1","", _
        "[CLASS:ListView20WndClass; INSTANCE:1]","GetItemCount")
        Call("mvtolist")
        For $O=1 To $LISTNUM
        ControlSend("WINDOW1","","","{UP}")
        Next
        For $S=1 To $LISTNUM
            WinActive("Rounting\Estimation")
            ControlClick("WINDOW1","","[CLASS:AfxOleControl42; INSTANCE:2]","Left",4)
            Sleep(150)
            Send("^c")
            $TEMPCLIP=ClipGet()
            $STRIPCLIP=StringStripWS($TEMPCLIP,$STR_STRIPALL)
            $TEMPARR=StringSplit($STRIPCLIP,"-")
            $FINALSTRING=String($TEMPARR[3]&"-"&$TEMPARR[4]&"-"&$TEMPARR[5])
            $LOCATION=_ArraySearch($MSTR_CHCK,$FINALSTRING)
            $MSTR_CHCK[$LOCATION][1] = 1
            _FileWriteFromArray(@ScriptDir&$GEN_DIR&$USER_LIGHT&"\MasterCheck.txt",$MSTR_CHCK)
            Sleep(400)
            Call("mvtolist")
            Sleep(100)
            ControlSend("WINDOW1","","","{DOWN}")
            Sleep(50)
        Next
    $MSTR_SRCH[$R][1] = 1
    _FileWriteFromArray(@ScriptDir&$GEN_DIR&$USER_LIGHT&"\MasterSearch.txt",$MSTR_SRCH)
    Sleep(250)
    ControlClick("WINDOW1","","[CLASS:AfxOleControl42s; INSTANCE:3]","Left",2)
    WinWait("Search")
    Sleep(500)
    ControlSend("Search","","[CLASS:AfxOleControl42; INSTANCE:1]",$USER_LIGHT&"-"&$MSTR_SRCH[($R+1)][0])
    Sleep(300)
    ControlClick("Search","","[CLASS:AfxOleControl42s; INSTANCE:1]","Left",2)
    $WINVAR=WinWait("[CLASS:#32770]","",3)
    If $WINVAR<>0 Then
        ControlClick("[CLASS:#32770]","","[CLASS:Button; INSTANCE:1]","Left",2)
        Sleep(250)
        ControlClick("WINDOW1","","[CLASS:AfxOleControl42s; INSTANCE:2]","Left",2)
        WinWait("WINDOW2")
        Sleep(100)
        ControlClick("WINDOW2","","[CLASS:AfxOleControl42; INSTANCE:3]","Left",4)
        ControlSend("WINDOW2","","[CLASS:AfxOleControl42; INSTANCE:3]","{BACKSPACE}")
        ControlSend("WINDOW2","","[CLASS:AfxOleControl42; INSTANCE:3]",$USER_LIGHT& _
        "-"&$MSTR_CHCK[0][0])
        Sleep(100)
        ControlClick("WINDOW2","","[CLASS:AfxOleControl42; INSTANCE:2]","Left",4)
        ControlSend("WINDOW2","","[CLASS:AfxOleControl42; INSTANCE:2]","{BACKSPACE}")
        ControlSend("WINDOW2","","[CLASS:AfxOleControl42; INSTANCE:2]",$USER_LIGHT& _
        "-"&$MSTR_SRCH[($R+1)][0]&"-"&$TEMPARR[5])
        ControlClick("WINDOW2","","[CLASS:AfxOleControl42s; INSTANCE:3]","Left",2)
        WinWait("Verify Copy","")
        ControlClick("Verify Copy","","[CLASS:Button; INSTANCE:1]","Left",2)
        Sleep(100)
    EndIf
    Next
EndIf

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
Link to comment
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!

Link to comment
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!

Link to comment
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
Link to comment
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:

Opt("SendKeyDownDelay",0)
    Opt("SendKeyDelay",30)

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...