Jump to content
Sign in to follow this  

More robust ControlSend

Recommended Posts


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 )

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.


Func Abort()
    $Abort = True
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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.