Need help with a simple script (send delays) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gspinks11
Posts: 6
Joined: 24 Jan 2022, 19:27

Need help with a simple script (send delays)

Post by gspinks11 » 24 Jan 2022, 19:48

So I need a script to send the keys on the keyboard in the following order.

"4"
then
"v"
then
"w"
then
"s"

There is one crucial point where i need the delay, which doesn't seem to work properly (maybe because of my key press and depress functions?)

After the "V" key is pressed/released i need the "W" key to be pressed EXACTLY 4 seconds after. The following key "s" just needs to be pressed immediately after. I think what I have may work but I'm still doubtful based on some testing. I'm close it seems but if anyone has more experience and can maybe clean this up or tweak it better for me or at least overlook it and offer input i would GREATLY appreciate it.

Code: Select all

Send {4 down}
Sleep 2000
Send {4 up}
Sleep 300  
Send {v down}
Sleep 300
Send {w down}
Sleep 4000
Send {s down}
Sleep 1
Send {s up}
Sleep 1
[Mod Edit: [code][/code] tags added]

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Need help with a simple script (send delays)

Post by mikeyww » 24 Jan 2022, 20:10

Welcome to this AutoHotkey forum!

From your script, it appears that W is sent 310 ms after V. It also appears that V is not released. Am I missing something?

There is no such thing as "exactly".

Code: Select all

Send {4 down}
Sleep 2000
Send {4 up}
Sleep 300
Send {v down}
start := A_TickCount
Sleep 300
Send {w down}
MsgBox, 64, Elapsed time, % A_TickCount - start " ms"
image220124-2015-001.png
Output
image220124-2015-001.png (6.75 KiB) Viewed 823 times

gspinks11
Posts: 6
Joined: 24 Jan 2022, 19:27

Re: Need help with a simple script (send delays)

Post by gspinks11 » 24 Jan 2022, 20:52

understood about the EXACTLY part but then if not exact i want as close as possible.

gspinks11
Posts: 6
Joined: 24 Jan 2022, 19:27

Re: Need help with a simple script (send delays)

Post by gspinks11 » 24 Jan 2022, 20:59

mikeyww wrote:
24 Jan 2022, 20:10
Welcome to this AutoHotkey forum!

From your script, it appears that W is sent 310 ms after V. It also appears that V is not released. Am I missing something?

There is no such thing as "exactly".

Code: Select all

Send {4 down}
Sleep 2000
Send {4 up}
Sleep 300
Send {v down}
start := A_TickCount
Sleep 300
Send {w down}
MsgBox, 64, Elapsed time, % A_TickCount - start " ms"

image220124-2015-001.png

so CLOSE ENOUGH to 4 seconds as possible is fine...

also, you can ignore that there is no release of the "V" key. I have it there for the rest of the commands as I was testing but it seems this isn't necessary for what I'm using this for. The release of the V key isn't actually necessary but it being there also doesn't hurt so whatever you prefer, that was never part of the issue from what I've tested so far.

and how did you get 310 ms for the W key? it set to 300 based on the above no??


lets work off this one BELOW instead as the first one i posted was a diff version that i didn't realize i posted lol sorry

Code: Select all

Send {4 down}
Sleep 2000
Send {4 up}
Sleep 300  
Send {v down}
Sleep 300
Send {v up}
Sleep 300
Send {w down}
Sleep 4000
Send {s down}
Sleep 1
Send {s up}
Sleep 1
[Mod Edit: [code][/code] tags added]




Does the SLEEP command need to FOLLOW the key? or does it go prior to the SEND command? Say i want to just delay key press the W key would it be,

Sleep 4000
Send {W down}


Or

Send {W down}
Sleep 4000

???

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Need help with a simple script (send delays)  Topic is solved

Post by mikeyww » 24 Jan 2022, 21:15

The commands occur in order. Sleep before send means... sleep first, and when the sleep is over, then the send occurs. Opposite is... the opposite. :) This is readily understood through a simple test script, I think.

The missing 10 ms is found in the Send command. By default, every key sent with SendEvent (the default Send mode) includes a 10 ms delay after the send.

gspinks11
Posts: 6
Joined: 24 Jan 2022, 19:27

Re: Need help with a simple script (send delays)

Post by gspinks11 » 24 Jan 2022, 21:18

mikeyww wrote:
24 Jan 2022, 21:15
The commands occur in order. Sleep before send means... sleep first, and when the sleep is over, then the send occurs. Opposite is... the opposite. :) This is readily understood through a simple test script, I think.

The missing 10 ms is found in the Send command. By default, every key sent includes a 10 ms delay after the send.
Thank you, my script works so the information you provided should help me get the timing correct which was my major issue with it so I appreciate your help and expertise, as well as timely reply!!!

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Need help with a simple script (send delays)

Post by mikeyww » 25 Jan 2022, 06:53

You are welcome.

Code: Select all

Send v ; After the "V" key is pressed/released i need the "W" key to be pressed EXACTLY 4 seconds after
vreleased := A_TickCount ;;;;;;;;;;;;;;;;;;
ToolTip, Please wait.... ;;;;;;;;;;;;;;;;;;
Sleep, 4000
wpressed := A_TickCount  ;;;;;;;;;;;;;;;;;;
Send w
ToolTip                  ;;;;;;;;;;;;;;;;;;
MsgBox, 64, Time elapsed, % wpressed - vreleased " ms"
image220125-0653-001.png
Output
image220125-0653-001.png (6.69 KiB) Viewed 723 times

Post Reply

Return to “Ask for Help (v1)”