Sign in to follow this  
Followers 0
PhilHibbs

More robust ControlSend

1 post in this topic

#1 ·  Posted (edited)

When using Send() or ControlSend(), it isn't guaranteed that text will go to the right place if something interrupts the operation. Another window might steal focus, or focus might be moved by an accidental mouse click. Simple cases, where you just want to set an Edit control to a particular value, can be dealt with like this:

const $ControlID  = "[CLASS:Edit; INSTANCE:1]"
const $Clear = "{HOME}+{END}{DEL}"

    While ControlGetText( $WindowText, "", $ControlID ) <> $ControlText And Not($Abort)
        ControlSend( $WindowText, "", $ControlID, $Clear & $ControlText )
    WEnd

You can extend this to multiple controls in two ways - individual While loops with a surrounding loop that checks them all, or just do away with the individual loops and have all the checks in one While and all the ControlSends inside the While.

If you have a more complex requirement, such as inserting text into a RichEdit control, then that is much more tricky and I don't really have an answer to that, but the above technique has made my application launcher much more robust.

The $Abort variable is a flag that I set in a HotKeySet() so that the user can interrupt an operation that is going haywire.

$Abort=False
HotKeySet("{Esc}","Abort")

Func Abort()
    HotKeySet("{Esc}")
    $Abort = True
EndFunc
Edited by PhilHibbs

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