我不明白,如何在不结束脚本的情况下多次使用来自Loop
的周期。
我有一个文件SashaAutoScrolling.ahk
,内容为:
; First loop, Speed 1
#+1::
Loop
{
Send {WheelDown}
Sleep 3000
}
; Second loop, Speed 2
#+2::
Loop
{
Send {WheelDown}
Sleep 600
}
; Third loop, Speed 3
#+3::
Loop
{
Send {WheelDown}
Sleep 100
}
; Fourth loop, Speed Up
#+0::
Loop
{
Send {WheelUp}
Sleep 600
}
; Loop pause
; http://autohotkey.com/board/topic/95308-endless-loop-with-hotkey-pause/?p=600526
#p::Pause
; Exit script
#esc::ExitApp
我在任何PDF查看器中打开任何pdf
文件。我在«速度»之间切换:
如果我第一次运行 Shift + Super + 3 和 Shift + Super + 0
我可以成功切换«速度»。
如果我按 Shift + Super + 3 和 Shift + Super + 0 第二次,
我无法在«速度»之间切换。
成功切换«速度»无限次。
djvu
或doc
本书。答案 0 :(得分:1)
在按下 Shift + Win + 1 , Shift + Win + 2 等模拟鼠标滚轮滚动时滚动当前窗口。 esc 退出循环
#+1:: scrollit(3000)
#+2:: scrollit(600)
#+3:: scrollit(300)
Esc:: abort()
scrollit(delay)
{
global abort := false
while (!abort)
{
Send {WheelDown}
Sleep delay
}
}
abort()
{
global abort := true
}
答案 1 :(得分:1)
此代码使用模拟鼠标滚轮滚动
滚动当前窗口Shift + Win + 1 , Shift + Win + 2 等...开始滚动。如果已经滚动,只需更新睡眠间隔。 esc 退出
; globals:
; g_running : true while loop is active
; g_sleep : milliseconds to sleep between sending input event
; g_key : key to simulate
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; HOTKEY DEFINITIONS
#MaxThreadsPerHotkey 2
#+1:: scrollit(3000)
#+2:: scrollit(600)
#+3:: scrollit(300)
#+0:: scrollit(600,"WheelUp")
#MaxThreadsPerHotkey 1
Esc:: abort()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; HELPER FUNCTIONS
; send wheeldown every _delay_ microseconds
; if called while loop is already active, just update delay and exit
;
scrollit(sleep, key="WheelDown")
{
global g_running
global g_sleep := sleep
global g_key := key
if g_running
return
g_running := true
while (g_running)
{
Send {%g_key%}
Sleep g_sleep
}
}
abort()
{
global g_running := false
}
答案 2 :(得分:0)
您的代码无法正常工作,因为默认情况下,每个热键只有一个主题。当你这样做时:
Loop
{
Send {WheelDown}
Sleep 100
}
你永远不会从这一个线程返回,所以当你第二次调用它时,热键不会触发,你的程序将继续在当前线程中循环。
Jim U通过调用#MaxThreadsPerHotkey 2
解决了这个问题,但这不会让你的代码工作,因为你根本不会从你的热键线程返回,Jim U没有&#39} ; t仅从第一个线程返回,因此2个线程足以让他的solutoin工作。
另一种解决方案是使用计时器,以下将立即改变滚动速度,不需要任何特殊指令,也不依赖于Autohotkeys独特的线程模型。
#+1::callSetTimer(3000)
#+2::callSetTimer(600)
#+3::callSetTimer(100)
#+0::callSetTimer(600, "WheelUp")
Esc::SetTimer, scrollTimer, Off
callSetTimer(interval, key := "WheelDown") {
global currKey := key
SetTimer, scrollTimer, %interval%
scrollTimer:
send, {%currKey%}
return
}