Autohotkey: I'm unable to make a script for pressing 2 keys with a delay beteween them

StackOverflow https://stackoverflow.com/questions/16684312

  •  30-05-2022
  •  | 
  •  

Question

Well i want to make a script with the objetive:

3{DOWN} key, and later hold or quickly press Z x3, and loop all that.

I have been trying to work with loop command but i just can't, im new with AutoHotkey and english it's not my native languague so it's been pretty hard.

Here is the code i tried but didn't work as i expect, since it press Z before the 3 {DOWN} keys.

#Persistent
SetTimer, Code, 150
Return

Code:
Send, Z{DOWN}
Return

If you know anyway to improve what i'm doing like, add a toggle like F8 to turn on/off, it would be aweosome.

Thanks for any help. Helena.

Was it helpful?

Solution

Helena, What your script does right now is the following. As soon as the script starts it will start to send [Z] and [Arrow down] every 150 mili seconds. This is independent of what application is running at that time. You write that you want to loop sending codes and that you want to toggle this ON/OFF.

Here is an example that comes closer to your goal.

#Persistent

F8:: ; This is your [F8] Toggle hotkey
If Toggle:=!Toggle ; Here you "test" the value of the variable "toggle" and after testing switch it to the opposite (true/false)
    SetTimer, Trigger, -1 ; This is to create a separate thread for the loop. -1 means start in 1 ms but only do this one time, not every 1 ms's.
return

Trigger:
While (Toggle)
{
    Send, +z{Down} ; + is the shift key, thus +z makes captial Z
    Sleep, 500 ; Wait 500 ms (1/2 a second)
    Send, +{z Down} ; Press Shift z Down. This will NOT start a repeat like ZZZZZZZZZZZZZZZZ
    Sleep, 500 ; Wait 500 ms (1/2 a second)
    Send, +{z Up} ; Lift Shift z Up
    Sleep, 1 ; Required. Without it The F8 keypress to toggle off can not be read anymore
}
Return
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top