Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-17-2012, 04:45 PM
freeborn freeborn is offline
Registered User
 
Join Date: Jan 2011
Posts: 2
WaitForCursor in milliseconds?

I am using WaitForCursor in my vbscript to pace the the script and ensure it doesn't get ahead of the host. Something like this:
Code:
   Do
     bCursorMoved = crt.Screen.WaitForCursor(1)
   Loop Until bCursorMoved = False
My problem is that the timeout of 1 second is too long - ideally I'd like to use milleseconds but I don't think that's possible.

Currently using SecureCRT 6.6.1.

I know that crt.Sleep uses milliseconds and I could probably write a couple of lines of script using Sleep to mimic the WaitForCursor function but is there some other method that I'm missing?

Seems like timeout in milliseconds would also be useful with WaitForStrings.
Could this be a future enhancement?
Reply With Quote
  #2  
Old 01-17-2012, 06:07 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,039
Hello,

I've added your suggestion for an option to wait for milliseconds instead of seconds, in WaitForCursor and WaitForStrings. We'll post here if implemented. Let us know if you would like to be notified via e-mail if implemented, and please refer to forum thread 10251.

Regarding a workaround, crt.Sleep may not the best option because it pauses script execution at that line until sleep ends. You should get better results using crt.Screen.WaitForCursor because it should return as soon as the cursor moves.

Because WaitForCursor returns as soon as the cursor moves... the granularity of time used shouldn't matter (for any scenario I can think of).

Why is a 1 second timeout too long for you?

The code example you posted loops on whether or not the cursor moved. The goal seems to be to wait for cursor movement, indefinitely. The one second timeout does not mean that the function will only return once per second. It will return immediately upon movement. In fact, depending on what else your code does, it might be better not to loop at all, and not use a timeout. It might be better to just use the maximum timeout you'd ever want to wait.

The following code demonstrates that as soon as the cursor moves the WaitForCursor method exits.
Code:
crt.Screen.WaitForCursor()
' Type a character or press the spacebar when you're ready to stop waiting
MsgBox "Cursor moved"
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #3  
Old 01-17-2012, 08:34 PM
freeborn freeborn is offline
Registered User
 
Join Date: Jan 2011
Posts: 2
Hi Michael

Thanks for the quick reply!

The script is used to change telephone programming on a CS1000 PBX which involves several prompts/responses per phone and seems to work best if you don't push it too fast.

My goal isn't to wait for cursor movement - it is to wait for NO cursor movement. My thinking was - if the cursor has stopped moving then the host is quiet and ready for input. The little WaitForCursor loop seems to do that very well but I don't need to wait for a full second - 300 msec would probably be enough. Otherwise it almost seems like I could type faster than the script.

In the past I have used Reflection which has a WaitForSilence method that worked well for this. But I'm hoping that I've missed some way in SecureCRT that I can do this.
Reply With Quote
  #4  
Old 01-18-2012, 03:15 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,039
Quote:
My goal isn't to wait for cursor movement - it is to wait for NO cursor movement. My thinking was - if the cursor has stopped moving then the host is quiet and ready for input.
Thank you for clarifying your goal and approach. I understand your thinking about waiting for the cursor to stop moving as a fairly consistent, accurate means of determining that the server is ready for input. Usually WaitForString, WaitForStrings, or ReadString will be used to wait for the command prompt on the server. The command prompt is usually an excellent indication that the host is ready for input. However, these functions do rely on screen data being synchronous (crt.Screen.Synchronous = True). The reason data should be synchronous for those functions is explained in the SecureCRT Scripting Manual, in the section 4.2 (see Avoid "Missing" Data with Screen.Synchronous = True).

If there is a lot of output and crt.Screen.Synchronous seems to be slowing down throughput to unacceptable levels, you may want to consider using an asynchronous method, as shown in the attached example script, WaitForScreenContentsToStopChanging.vbs. The script uses an approach along the lines you suggested, waiting for silence.

If you run the script from SecureCRT you'll be prompted for a timeout interval which you can set, and a command to run. After the command is issued, the script watches asynchronously for data stop changing for the duration of the timeout interval.

Once acceptable and consistent timeout periods are found, the timeout intervals could simply be hard coded into the heart of the script, which is the subroutine WaitForScreenContentsToStopChanging.

Quote:
In the past I have used Reflection which has a WaitForSilence method that worked well for this. But I'm hoping that I've missed some way in SecureCRT that I can do this.
WaitForSilence sounds like it could be useful. I'll add a feature request on your behalf for something similar to be added to SecureCRT's scripting API. As before, if implemented we'll post a follow up message here, but let us know (and refer to forum thread 10251) if you'd like e-mail notification as well, if implemented.
Attached Files
File Type: txt WaitforScreenContentsToStopChanging.txt (3.7 KB, 677 views)
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]

Last edited by jdev; 01-18-2012 at 04:17 PM.
Reply With Quote
  #5  
Old 11-19-2018, 05:18 PM
Maureen's Avatar
Maureen Maureen is offline
VanDyke Product Director
 
Join Date: Feb 2004
Location: Albuquerque, NM
Posts: 1,612
The ability to specify a timeout value in milliseconds for the script functions WaitForCursor, WaitForKey, WaitForString, and WaitForStrings has been added to a pre-beta version of SecureCRT.

Please email me at Maureen.Jett@vandyke.com if you would be interested in trying it.

Maureen
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 01:52 AM.