WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: snowsnowsnow on November 05, 2013, 01:35:01 PM

Title: Sendkey: Looking for definitive answers...
Post by: snowsnowsnow on November 05, 2013, 01:35:01 PM
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)
Title: Re: Sendkey: Looking for definitive answers...
Post by: Deana on November 05, 2013, 03:19:12 PM
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
Title: Re: Sendkey: Looking for definitive answers...
Post by: snowsnowsnow on November 05, 2013, 07:59:32 PM
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.
Title: Re: Sendkey: Looking for definitive answers...
Post by: Deana on November 06, 2013, 08:19:10 AM
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.
Title: Re: Sendkey: Looking for definitive answers...
Post by: snowsnowsnow on November 06, 2013, 03:43:35 PM
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.