如何并行启动2个循环?

How to start 2 loops in parallel?

我正在尝试执行以下操作:

~e::
while GetKeyState("e","P")
{
    Send {1 Down}
    Sleep 500
    Send {1 Up}
}

while GetKeyState("e","P")
{
    Send {2 Down}
    Sleep 1000
    Send {2 Up}
}

return

注意睡眠差异。仅执行键 1 循环。

我尝试了 gosub-s 和 goto-s,但它们只是随后启动。如何在按下一个键的同时开始并保持 2 个循环 运行?

谢谢。

Autohotkey 不能[同时]和[在同一个脚本中]进行循环

你可以做的是使用单独的两个 Ahk 脚本,一起你可以同时(parralel)做循环,

你可以试试这个代码:

; [+ = Shift] [! = Alt] [^ = Ctrl] [# = Win] 
#notrayicon
#SingleInstance force


ConvertAndRun1("~e:: | while GetKeyState('e','P') | { | Send {1 Down} | Sleep 500 | Send {1 Up} | } | return | ~esc::exitapp")
ConvertAndRun2("~e:: | while GetKeyState('e','P') | { | Send {2 Down} | Sleep 1000 | Send {2 Up} | } | return | ~esc::exitapp")
exitapp

ConvertAndRun1(y)
{
FileDelete, Runscript1.ahk
;a - [Convert String into single codelines with return] - [Char | is the breakline.]
StringReplace,y,y, |, `n, all
StringReplace,y,y, ', ", all
sleep 150

;b - Save String to Ahk file 
x:=";#notrayicon `n #SingleInstance force `n "
z:="`n "
FileAppend, %x%%y%%z%, Runscript1.ahk
sleep 150

;c - Now it can Run all these commands from that Ahk file.
run Runscript1.ahk
sleep 150
}


ConvertAndRun2(y)
{
FileDelete, Runscript2.ahk
;a - [Convert String into single codelines with return] - [Char | is the breakline.]
StringReplace,y,y, |, `n, all
StringReplace,y,y, ', ", all
sleep 150

;b - Save String to Ahk file 
x:=";#notrayicon `n #SingleInstance force `n "
z:="`n "
FileAppend, %x%%y%%z%, Runscript2.ahk
sleep 150

;c - Now it can Run all the commands from that ahk file.
run Runscript2.ahk
sleep 150
exitapp
}

注:

1 - 我确实制作了一个脚本,可以将带有多个命令的单行 (Linebreaks=|) 转换为单个 Ahk 文件。

2 - 在单行中,您需要使用 ['] 而不是双引号 ["]

3 - 使用 [Esc] 键可以停止这两个脚本。