Sign in to follow this  
Followers 0
antan

WinWaitDelay and ControlClick and Calculator timing

7 posts in this topic

#1 ·  Posted (edited)

Hello,

I have some questions..

I was trying to make fast scripts by cutting off delays between window operations using Opt("WinWaitDelay", 0).

And for a test, I tried running the windows calculator and clicking the number 1 button using the following code:

Opt("WinWaitDelay", 0)
ShellExecute("calc.exe")
WinWaitActive("Calc")
ControlClick("Calc","","Button44")

Then I ran the script like 10-15 times to make sure it is working 100%.

(using only one instance of calculator and closing the calculator manually after each run)

But I found that on rare occasions, 0 remains in the calculator display field instead of 1.

Which means that somehow the ControlClick function is not always working.

I then tried other functions like Send("1") and ControlSend("Calc","","Button44","{SPACE}") instead of ControlClick and tested the script 10-15 times again, and found that these two always works.

I know that I can simply use one of the other two working methods, but I am just curious about why ControlClick didn't work.

Can someone give me the explanation?

---------------------

Also, is my understanding of WinActivate and WinWaitActive below correct?

Opt("WinWaitDelay", 0)
ShellExecute("calc.exe")
WinWait("Calc")
WinActivate("Calc")
Send("1")

The code above might not always work because WinActivate does not ensure that the window is activated completely and is ready to recieve input.

It just sends the activate command and passes to the next line in the script immediately.

Opt("WinWaitDelay", 0)
ShellExecute("calc.exe")
WinWaitActive("Calc")
Send("1")

The code above will always work because WinWaitActive pauses the script until the window is activated completely and is ready to recieve input, it passes to the next line only after that.

Edited by antan

Share this post


Link to post
Share on other sites



Hi,

your problem is selfmade :P

By set the delay to 0 ControlClick can't work steadily.

So i've never got a failed click:

$old = Opt("WinWaitDelay", 10)
ShellExecute("calc.exe")
WinWait("[CLASS:SciCalc]")
ControlClick("[CLASS:SciCalc]","","[CLASSNN:Button44]")
Opt("WinWaitDelay", $old)
Exit

Best Regards BugFix  

Share this post


Link to post
Share on other sites

Hi BugFix, thanx for replying

I tried your code but even with Opt("WinWaitDelay", 10), 0 still remains in the display field sometimes.

The probability becomes extremely rare though.

Anyway, I tried ControlClick with 2 more programs, MS Paint and Character Map.

Below are the codes and their results:

Opt("WinWaitDelay", 0)
ShellExecute("mspaint.exe")
WinWaitActive("untitled - P")
ControlClick("untitled - P","","AfxWnd42u2","",1,17,13); click the "Free-Form Select" button

Result: always clicked.

Opt("WinWaitDelay", 0)
ShellExecute("charmap.exe")
WinWaitActive("Char")
ControlClick("Char","","Button1"); click the "Select" button

Result: same as calculator, sometimes not clicked.

I wonder why it always works with this AfxWnd42u2 thing in MS Paint... maybe because it's not a button control??

and also why ControlSend works where ControlClick doesn't..

I guess Send is more reliable than Click..

And do you happen to know the answer to my 2nd question?

(is my understanding of WinActivate and WinWaitActive below correct?)

thanx :P

Share this post


Link to post
Share on other sites

Yes your understanding of WinActivate and WinWaitActive is correct. WinWaitActive will wait. As indicated by BugFix, the program may have not fully loaded.

In my opinion it is always better to use Send or ControlSend over the mouse. I would recommend you look at WinGetHandle. This will give you greater control over your programs with control functions.

Hope that helps.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

thankx bo8ster,

It really helped :P

Will check the WinGetHandle function.

Edited by antan

Share this post


Link to post
Share on other sites

I had this problem as well. The application takes some time to load and would sometimes appear behind other windows. Using the simple built-in functions was not enough. The following works a lot better:

http://pastie.org/421196

Share this post


Link to post
Share on other sites

Hi chetan,

Now thats a lot of do and Untils! :P!

I hope it can be made a bit simpler like below?:

$title = "QuickBooks Database Server Manager"

Run("C:\Program Files\Common Files\Intuit\QuickBooks\QBServerUtilityMgr.exe")

WinWait($title) ;wait for the window to exist
WinActivate($title) ;send activate command
WinWaitActive($title, "loaded..") ;wait untill activated.
;you can put a text in place of loaded.. from the $title window which might indicate that the program is fully loaded (if there is any)
;find out using AutoIt Window Info tool

;Sleep(250) ; optional sleep if it still does not work

;ControlClick($title, "", "[TEXT:Scan]")
;since it appears that send is more reliable than click, maybe it's better to use Send or ControlSend instead of ControlClick like the following
;Send("!s") ; replace !s with the keyboard shortcut of the scan button if available..
ControlSend($title, "", "[TEXT:Scan]", "{SPACE}")

WinWaitActive($title,"Folder scan complete.")

;Sleep(250) ; optional sleep if it still does not work

;same as the ControlClick above
;ControlClick($title, "", "[TEXT:Close]")
;Send("!c") ;
ControlSend($title, "", "[TEXT:Close]", "{SPACE}")

good luck :unsure:

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