Page 1 of 1

why some scripts spam do not work unless with sleep(50) in some app?

Posted: 05 Dec 2023, 02:30
by xMaxrayx
Hi ,Can someone tell me why I need to use sleep(50) for same app to make sure my script will work flawlessly?
like this following script do NOT work with "vs code" but it works fine with "notepad++" (in spammy way)

Code: Select all

horizontalFunc(code, clipMethod := "^v" , codeEnd:="", EnterMethod := " {Enter}" ,AllowAutoPaste := true){
local textOutput := (code . codeEnd) 
A_Clipboard := textOutput

if AllowAutoPaste := true {
    send(clipMethod)
    Send(EnterMethod)
}
}



it won't work on VS.code unless I add sleep(50)

Code: Select all

horizontalFunc(code, clipMethod := "^v" , codeEnd:="", EnterMethod := " {Enter}" ,AllowAutoPaste := true){
local textOutput := (code . codeEnd) 
A_Clipboard := textOutput

if AllowAutoPaste := true {
    send(clipMethod)
    sleep(50) ;=====================here new line
    Send(EnterMethod)
}


}



why this happened?

Re: why some scripts spam do not work unless with sleep(50) in some app?  Topic is solved

Posted: 05 Dec 2023, 04:22
by gregster
Such applications are simply not optimized to get automated by AHK's simulated keystrokes. For various reasons, they might have different methods of processing user input, and different controls; and some are more sluggish than others. Also, autcomplete and similar features often get into the way.

That's why AHK offers different send modes and allows to change key press duration and key delay, or to add sleeps - because it's often a matter of trial-and-error.

Re: why some scripts spam do not work unless with sleep(50) in some app?

Posted: 10 Dec 2023, 02:06
by xMaxrayx
gregster wrote:
05 Dec 2023, 04:22
Such applications are simply not optimized to get automated by AHK's simulated keystrokes. For various reasons, they might have different methods of processing user input, and different controls; and some are more sluggish than others. Also, autcomplete and similar features often get into the way.

That's why AHK offers different send modes and allows to change key press duration and key delay, or to add sleeps - because it's often a matter of trial-and-error.
I see many thanks <3