自动热键切换脚本
Autohotkey Toggle script
我只是想用相同的键映射 (Ctrl + I) 切换命令:
#InstallKeybdHook
#UseHook
^i::
send, BLABLABLA
return
如果我按 Ctrl+I,它会输入 BLABLABLA(当然),我想让它以一定的间隔(180 秒)重复,我希望它被切换。怎么做?
您将要使用 a timer。
而且我不确定您为什么要使用这两个 #directives,它们没有为该脚本做任何有用的事情。
但是关于使用定时器:
SetTimer, TimerCallback, 180000
这将创建一个计时器,每 180,000 毫秒(180 秒)触发一次函数(或标签)TimerCallback
。
当然,我们还没有定义函数 TimerCallback
,所以让我们现在开始吧:
TimerCallback()
{
Tooltip, hi
}
然后在热键上切换计时器 on/off:
^i::
toggle := !toggle ;a convenient way to toggle a variable in AHK, see below of explanation
if (toggle) ;if true
{
SetTimer, TimerCallback, 180000 ;turn on timer
;the function will only run for the first timer after
;those 180 secs, if you want it to run once immediately
;call the function here directly:
TimerCallback()
}
else
SetTimer, TimerCallback, Off ;turn off timer
return
toggle := !toggle
变量状态切换的解释可以从我之前的回答中找到here。
还包括一个可爱的小 1liner 计时器切换热键的示例。
下面是完整的示例脚本:
^i::
toggle := !toggle ;a convenient way to toggle a variable in AHK, see below of explanation
if (toggle) ;if true
{
SetTimer, TimerCallback, 180000 ;turn on timer
;the function will only run for the first timer after
;those 180 secs, if you want it to run once immediately
;call the function here directly:
TimerCallback()
}
else
SetTimer, TimerCallback, Off ;turn off timer
return
TimerCallback()
{
Tooltip, hi
}
我只是想用相同的键映射 (Ctrl + I) 切换命令:
#InstallKeybdHook
#UseHook
^i::
send, BLABLABLA
return
如果我按 Ctrl+I,它会输入 BLABLABLA(当然),我想让它以一定的间隔(180 秒)重复,我希望它被切换。怎么做?
您将要使用 a timer。
而且我不确定您为什么要使用这两个 #directives,它们没有为该脚本做任何有用的事情。
但是关于使用定时器:
SetTimer, TimerCallback, 180000
这将创建一个计时器,每 180,000 毫秒(180 秒)触发一次函数(或标签)TimerCallback
。
当然,我们还没有定义函数 TimerCallback
,所以让我们现在开始吧:
TimerCallback()
{
Tooltip, hi
}
然后在热键上切换计时器 on/off:
^i::
toggle := !toggle ;a convenient way to toggle a variable in AHK, see below of explanation
if (toggle) ;if true
{
SetTimer, TimerCallback, 180000 ;turn on timer
;the function will only run for the first timer after
;those 180 secs, if you want it to run once immediately
;call the function here directly:
TimerCallback()
}
else
SetTimer, TimerCallback, Off ;turn off timer
return
toggle := !toggle
变量状态切换的解释可以从我之前的回答中找到here。
还包括一个可爱的小 1liner 计时器切换热键的示例。
下面是完整的示例脚本:
^i::
toggle := !toggle ;a convenient way to toggle a variable in AHK, see below of explanation
if (toggle) ;if true
{
SetTimer, TimerCallback, 180000 ;turn on timer
;the function will only run for the first timer after
;those 180 secs, if you want it to run once immediately
;call the function here directly:
TimerCallback()
}
else
SetTimer, TimerCallback, Off ;turn off timer
return
TimerCallback()
{
Tooltip, hi
}