AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Inconsistent Behavior w/ControlSetText and ControlSend

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
dclayton



Joined: 25 Apr 2005
Posts: 1

PostPosted: Mon Apr 25, 2005 1:36 pm    Post subject: Inconsistent Behavior w/ControlSetText and ControlSend Reply with quote

Hello,

I am trying to write a simple script which manipulates a custom application built with PowerBuilder. For some reason, I get very inconsistent behavior when it comes to setting text on a control. Here's a sample:

Code:

    hWinLogon := getLogonWindow(applicationPID)
    WinActivate, ahk_id %hWinLogon%
    sleep, 50
    ControlSend, textBox2, hello, ahk_id %hWinLogon%
    Sleep, 1000
    ControlGetText, currentTextValue, textBox2, ahk_id %hWinLogon%
    MsgBox, %ErrorLevel% : %currentTextValue%


Approximately 50% of the time, MsgBox returns "0 : ". The other times it returns "0 : hello, s".

I also tried the following code:

Code:

    hWinLogon := getLogonWindow(applicationPID)
    WinActivate, ahk_id %hWinLogon%
    sleep, 50
    ControlSetText, textBox2, hello, ahk_id %hWinLogon%
    Sleep, 1000
    ControlGetText, currentTextValue, textBox2, ahk_id %hWinLogon%
    MsgBox, %ErrorLevel% : %currentTextValue%


This statement always returns "0 : hello", but for some reason, no text appears in the actual text box. I can get the text to magically appear by sending a "left cursor" key to the text box.

So I have a few questions:

1. Why does ControlSend populate the text box with "hello, s" instead of "hello"?

2. Why does ControlSend only work 50% of the time?

3. Why does ControlSetText not graphically update the text within the actual text box?

I am running Windows XP Service Pack 2.

Many thanks,

dclayton
Back to top
View user's profile Send private message
TeknoMusicMan



Joined: 14 Apr 2005
Posts: 188
Location: Wisconsin, USA

PostPosted: Mon Apr 25, 2005 4:39 pm    Post subject: Reply with quote

1. Run AutoIt3 Window Spy and check to make sure the edit box's name is actually textBox2. It probably doesn't follow that naming standard. Most likely it's Edit1 or Edit2, something like that.

2. Try using ControlSetText instead of ControlSend. This works flawlessly for me when I use it.

3. Try testing out your script with the actual title of the window, maybe ahk_id won't work if the program has some sort of weird parent/child window stuff going on.

4. Check that the text box actually had the text sent to it. I usually make a loop with a if statment in it that checks to see if the text is "blah" and if it doesn't match "blah" it does controlsettext again, and it keeps looping untell the text matches "blah" then the loop exits. Its like double checking your work Very Happy


I hope that helps you out.
_________________

"Make it idiot-proof, and someone will make a better idiot."
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Tue Apr 26, 2005 11:10 am    Post subject: Reply with quote

Also, ControlSend might become more reliable for certain types of applications if you increase key-delay to the following:
SetKeyDelay, 10, 10

If the above helps, you could also try speeding it up with:
SetKeyDelay, 0, 10
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group