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

Discuss Autohotkey related topics here. Not a place to share code.
Forum rules
Discuss Autohotkey related topics here. Not a place to share code.
User avatar
xMaxrayx
Posts: 203
Joined: 06 Dec 2022, 02:56
Contact:

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

Post by xMaxrayx » 05 Dec 2023, 02:30

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?
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

gregster
Posts: 9085
Joined: 30 Sep 2013, 06:48

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

Post by gregster » 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.

User avatar
xMaxrayx
Posts: 203
Joined: 06 Dec 2022, 02:56
Contact:

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

Post by xMaxrayx » 10 Dec 2023, 02:06

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
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

Post Reply

Return to “General Discussion”