Sign in to follow this  
Followers 0
jhbell

Help with Send

6 posts in this topic

Keeping Focus on a Window

I'm trying to develop some scripts to automate my common tasks under Windows.

From time to time I need to SEND characters to a window but if another task steals the active window in the middle of my script the characters get sent to it instead. This is happenning when IE activates in the middle of my script

My quick fix was to keep issuing WINACTIVATE just before the SEND, but I'm concerned that this is not fool proof. ie: can focus get stolen between the two commands?

Another thought was to do a WINGETTEXT of my window before the SEND and a WINGETTEXT of the active window after the send and compare window text that the send would not have changed. If it does change, go back and send again. This of course does not address the impact of the sent characters on the stealing window!

Is all this necessary? As it stands now seems the Send Command is useless in developing bug free scripts. If so this needs to be highlighted in the HELP. Why isn't it SEND ('title','txt','string to send')

I know we have ControlSend with focus so why have a SEND that is indeterminant? Am I missing something?

Share this post


Link to post
Share on other sites



I know we have ControlSend with focus so why have a SEND that is indeterminant? Am I missing something?

Some applications do not use standard controls, or will prevent standard automation. In those cases, a "global" system-wide send is required. However, for applications that do use standard controls, a ControlSend is often a better choice for the reasons you've provided above.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

you can always blockinput, so they can't mess things up (pesky users) I wrote a little udf I'd called ensureactive that took the $title, $text and did a combo of winwait, winactivate, winwaitactive, fairly being sure that the window is up bfore continuing... still vulnerable to someone clicking at the wrong second...


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I think there is a Solution!!! someone pointed out in another topic that ControlSend WITHOUT a control specification seems to work.

Nope..I tried it and it no-ops. I'll chase down the other post.

Edited by jhbell

Share this post


Link to post
Share on other sites

any solution found for this send problem? I am also facing similar problem and hunting for solution...

if anybody has, pl let me know

Share this post


Link to post
Share on other sites

I think there is a Solution!!! someone pointed out in another topic that ControlSend WITHOUT a control specification seems to work.

Nope..I tried it and it no-ops. I'll chase down the other post.

It works fine for me using a command prompt. See the following code. It will open a command prompt window, and ControlSend to it once it is opened. Then, it will minimize the window and do a 2nd ControlSend before restoring the window. This shows that you can indeed send to a window with no control.

Please also keep in mind it depends on the application, and how it captures keystrokes. This means it won't always work on all applications. However, the example works fine.

Run(@ComSpec)
WinWait(@ComSpec)
ControlSend(@ComSpec, "", "", "echo test one{ENTER}")
WinSetState(@ComSpec, "", @SW_MINIMIZE)
ControlSend(@ComSpec, "", "", "echo test two{ENTER}")
WinSetState(@ComSpec, "", @SW_RESTORE)

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

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