Sign in to follow this  
Followers 0
XcKyle93

One giant Send() call vs. many smaller Send() calls

3 posts in this topic

Hello,

I am new to AutoIt, and this is my first post on these forums. I just have a brief question regarding the Send() function, and how I use it in my code.

The task that I am trying to automate requires a long sequence of keystrokes, one right after the other.  I could just put all of the keystrokes  into one string, and pass that to the Send() function. However, I've decided to break my one Send() call up into many smaller Send() calls instead, one right after the other. 

Why do I do this? For readability and understanding.  Otherwise, I just have one giant line with a Send() call that is very hard to dissect/understand, even with comments.  My question, however, is the following: would this make my program noticeably less efficient? I don't know how much overhead is involved in calling Send(), much less any function in AutoIt, but is it enough to make a difference after a myriad of Send() calls?  An excerpt from my program is below (this part is in a loop actually):

Send("{ALT}m") ; Access Music Tools -> Options menu
    Send("e") ; Select end point of video
    Send("^c") ; Copy time
    Send("{ESC}") ; Exit text box
    Send("{ALT}v") ; Select Video Tools -> Edit
    Send("d") ; Select duration of video
    Send("^v") ; Paste time
    Send("{BS}{ENTER}") ; remove "s" so time is purely numerical

Also, a bit unrelated to the topic at hand, but is there much of a difference between using, say, ^ vs. {CTRL} for the CTRL key? I know that, for example, this allows for easier repition, e.g. {CTRL 4}, but is there any difference in delay per keystroke between Send("{CTRL}c") and Send("^c")?

Thanks,

Kyle

Share this post


Link to post
Share on other sites



Hi,

Welcome to the autoit forum :)

There is no real code efficiency difference by using the Send function multiple times instead of one time.

You can check it with this simple script :

Local $hTimer = TimerInit()

Send("{ALT}m" & _
"e" & _
"^c" & _
"{ESC}" & _
"{ALT}v" & _
"d" & _
"^v" & _
"{BS}{ENTER}")

ConsoleWrite(Round(TimerDiff($hTimer) / 1000, 4) & " secs" & @CrLf)

$hTimer = TimerInit()

Send("{ALT}m")
Send("e")
Send("^c")
Send("{ESC}")
Send("{ALT}v")
Send("d")
Send("^v")
Send("{BS}{ENTER}")

ConsoleWrite(Round(TimerDiff($hTimer) / 1000, 4) & " secs" & @CrLf)

Also, a bit unrelated to the topic at hand, but is there much of a difference between using, say, ^ vs. {CTRL} for the CTRL key? I know that, for example, this allows for easier repition, e.g. {CTRL 4}, but is there any difference in delay per keystroke between Send("{CTRL}c") and Send("^c")?

The {CTRL} key macro does not exists, it's whether {LCTRL} or {RCTRL}.

^ is used for key combination, it will be pressed until the other keys are sent, wherease the macros listed above will only send the ctrl key.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Each of the commands you are sending need to be completed before each subsequent call to the Send function. If it was only text being sent then you could possibly make your code more compact by sending all the text in one hit. Readabiliy and consistancy are also important: if dividing the text into chunks makes it easier to understand then do that instead.

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