如果在 autohotkey 中给出了相同的输入,如何重复正在进行的脚本
How to repeat an ongoing script if the same input is given in autohotkey
我使用此代码使用一个槽口发送更多鼠标滚轮滚动,问题是在循环完成之前再次发送输入时,没有考虑到这一点,循环需要在重新启动之前结束
我尝试寻找一种方法在有输入的情况下分解代码并重新启动它但没有成功
WheelUp::
loop 100
{
sendInput {WheelUp}
sleep 2
}
return
预期行为:在第 50 次循环中,如果再次给出输入,则重置循环计数(停止并重新启动脚本)以便总重复次数为 150
我无法回复其他评论,但 WheelUp::Send, {WheelUp 100}
不会打破当前的 100 个 Wheelup,并且会再添加 100 个 WheelUp。因此,如果在第 50 个 WheelUp 上再次给出输入,它仍然会发送 200 个 WheelUps。
在循环中,您将需要一个条件语句来检测最近是否检测到物理向上滚动,如果检测到则重新启动循环。对于大多数键,您将使用 GetKeyState
作为 if 语句中的检查,但是鼠标滚轮没有可检测的状态。
在我的示例代码中,Enter 按钮将重新启动循环。我不确定如果再次尝试使用 WheelUp 时如何重新启动循环,因为没有状态可检测,并且 A_TimeSincePriorHotkey
不可靠,因为循环正在发送 WheelUps。
WheelUp::
loop 100
{
sendInput {WheelUp}
sleep 2
if (GetKeyState("Enter", "P"))
Goto WheelUp
}
return
试试这个方法。
您必须更改 #MaxThreadsPerHotkey 设置。
This setting is used to control how many "instances" of a given hotkey
or hotstring subroutine are allowed to exist simultaneously. For
example, if a hotkey has a max of 1 and it is pressed again while its
subroutine is already running, the press will be ignored.
这将允许热键 "interupt" 本身。
每次在热键已激活时向上滚动,它都会在循环中再添加 100 次滚动。
#MaxThreadsPerHotkey 2
WheelUp::
if (counter > 0) ; this means the hotkey is already active
{
counter := counter + 100 ; in that case we just add another 100 scrolls to the loop
return
}
else ; this means the hotkey is not active, we start fresh with 100 scrolls
{
counter := 100
}
while, counter > 0
{
sendinput, {WheelUp}
sleep 40 ; change this to your requirement
counter--
; tooltip, % counter ; un-comment this line for testing
}
return
~WheelDown::counter := 0 ; extra hotkey to stop the loop immediately if needed
我使用此代码使用一个槽口发送更多鼠标滚轮滚动,问题是在循环完成之前再次发送输入时,没有考虑到这一点,循环需要在重新启动之前结束
我尝试寻找一种方法在有输入的情况下分解代码并重新启动它但没有成功
WheelUp::
loop 100
{
sendInput {WheelUp}
sleep 2
}
return
预期行为:在第 50 次循环中,如果再次给出输入,则重置循环计数(停止并重新启动脚本)以便总重复次数为 150
我无法回复其他评论,但 WheelUp::Send, {WheelUp 100}
不会打破当前的 100 个 Wheelup,并且会再添加 100 个 WheelUp。因此,如果在第 50 个 WheelUp 上再次给出输入,它仍然会发送 200 个 WheelUps。
在循环中,您将需要一个条件语句来检测最近是否检测到物理向上滚动,如果检测到则重新启动循环。对于大多数键,您将使用 GetKeyState
作为 if 语句中的检查,但是鼠标滚轮没有可检测的状态。
在我的示例代码中,Enter 按钮将重新启动循环。我不确定如果再次尝试使用 WheelUp 时如何重新启动循环,因为没有状态可检测,并且 A_TimeSincePriorHotkey
不可靠,因为循环正在发送 WheelUps。
WheelUp::
loop 100
{
sendInput {WheelUp}
sleep 2
if (GetKeyState("Enter", "P"))
Goto WheelUp
}
return
试试这个方法。
您必须更改 #MaxThreadsPerHotkey 设置。
This setting is used to control how many "instances" of a given hotkey or hotstring subroutine are allowed to exist simultaneously. For example, if a hotkey has a max of 1 and it is pressed again while its subroutine is already running, the press will be ignored.
这将允许热键 "interupt" 本身。 每次在热键已激活时向上滚动,它都会在循环中再添加 100 次滚动。
#MaxThreadsPerHotkey 2
WheelUp::
if (counter > 0) ; this means the hotkey is already active
{
counter := counter + 100 ; in that case we just add another 100 scrolls to the loop
return
}
else ; this means the hotkey is not active, we start fresh with 100 scrolls
{
counter := 100
}
while, counter > 0
{
sendinput, {WheelUp}
sleep 40 ; change this to your requirement
counter--
; tooltip, % counter ; un-comment this line for testing
}
return
~WheelDown::counter := 0 ; extra hotkey to stop the loop immediately if needed