Sendkey: Looking for definitive answers...

Started by snowsnowsnow, November 05, 2013, 01:35:01 PM

Previous topic - Next topic

snowsnowsnow

I think I know what happens, based on testing, but I'm looking for "definitive" (aka, from the horse's mouth) answers from the WB implementors.

What is the defined result of doing SendKey with:

1) A nonsense string.  E.g., {Foobar}

2) Something with a trailing blank.  E.g. {Up }

Is the answer:

1) Just ignored
2) Error message (and program abort)
3) Something else...

Note that #2 in the first list could come about if you wrote something like:

SendKey("{Up %foo%}")

where foo is supposed to be the number of Up's to send, but what if foo is undefined (in a particular run of the program) ?  (And, yes, I know there are workarounds to make sure this doesn't happen, but that's not the point)

Deana

Sendkey and SendKeysTo would simply ignore both 1 (non sense string) and 2 (trailing blank).

Confirmed using this simple code sample:

Code (winbatch) Select
Run( 'notepad.exe', '' )
WinWaitExist('~Notepad', 5)
SendKeysTo( '~Notepad', '{Foobar}' )  ;IGNORED

SendKeysTo( '~Notepad', '{Enter}{Enter}' )
SendKeysTo( '~Notepad', '{UP }' )  ;Up with trailing space will be IGNORED
Deana F.
Technical Support
Wilson WindowWare Inc.

snowsnowsnow

So, just to confirm: If I write SendKey("{Up }")
it does nothing (sends no keys - generates no error).  Right?

Which leads to: Is the optimal?  Is there any particular reason why it doesn't throw an error for garbage input?

I ask, because the usual WB model is to throw errors (and usually, to abort the program) anytime something goes the least bit wrong.

Deana

Yes if you specify invalid string inside curly braces{} it will be ignored. That function has been around for 'eons', so I cannot say if the developers had a particular reason why they decided to ignore rather than error. Often the decision to not error is to provide better user experience, by having the script to recover transparently from an error OR another possibility is that it was simply overlooked while coding the function.
Deana F.
Technical Support
Wilson WindowWare Inc.

snowsnowsnow

Thanks, Deana.  That answers all my questions.

So, I can safely put "{Up }" in and rest assured that it won't do anything...  That's good.