#p::Pause ; Pressing Win+P once will pause the script. Pressing it again will unpause.
Code: Select all
#p::Pause
#p::Pause ; Pressing Win+P once will pause the script. Pressing it again will unpause.
Code: Select all
#p::Pause
Code: Select all
3 ways to pause/unpause:
1) #p:: using "Pause()"; have to manually unpause
2) #q:: using "#MaxThreadsPerHotkey 2" and pause(); but I guess this will affect all other
hotkeys until I reset it to 1 after unpause...
3) #r:: using "Pause( ,true)": (I believe) this pauses the thread that I just interrupted,
so I suspect if I have multiple active threads, I could end up pausing the wrong one.
I guess if that becomes a problem, maybe I can read the previous entry in the callstack
and if it's not the correct thread, sleep and then try again?
*/
;
KeyHistory
#p::
{
Pause() ; After pressing "#p", refresh the KeyHistory window:
; Paused threads: 1 of 1 (1 layers)
; Since default for "#MaxThreadsPerHotkey" is 1, pressing the hotkey again ("#p")
; has no effect because this thread is paused.
; 1) Put a breakpoint on "x:=1".
; 2) Manually uncheck "Pause" in this script's systray icon
KeyHistory
Sleep 100
x:=1 ; 3) When breakpoint is triggered, KeyHistory should show:
; Paused threads: 0 of 1 (0 layers)
return
} ; Pressing Win+P once will pause the script. Pressing it again will unpause.
#MaxThreadsPerHotkey 2
#q::
{
Pause() ; After pressing "#q", refresh the KeyHistory window:
; Paused threads: 1 of 1 (1 layers)
; Press CTRL/h for "Hotkeys and their methods" window:
; Type Off? Level Running Name
; -------------------------------------------------------------------
; k-hook #p
; k-hook 1 #q
; Single step in debugger:
; Since "#MaxThreadsPerHotkey" is now 2, pressing the hotkey again ("#q")
; will launch a new thread, interrupting the first paused thread:
; 1) Press the hotkey again ("#q")
KeyHistory
x:=2 ; 2) KeyHistory should show:
; Interrupted threads: 1 (preempted: ...
; Paused threads: 0 of 2 (1 layers)
; If I could press CTRL/h for "Hotkeys and their methods" window:
; Type Off? Level Running Name
; -------------------------------------------------------------------
; k-hook #p
; k-hook 2 #q
; Examine stack to see 2 x "#q thread"
; After the 2nd thread finishes, the original "#q" (paused but then unpaused
; as a result of the second "#q" thread launching) will continue to execute
; on the next statement after "Pause()"
return
}
#MaxThreadsPerHotkey 1
#r::
{
Pause(, true) ; "If there is no thread beneath the current thread (SA: i.e. another thread
; wasn't interrupted because this is the only running thread), the script
; itself is paused, which prevents timers from running (this effect is the
; same as having used the menu item "Pause Script" while the script has no
; threads)."
; After pressing "#r", refresh the KeyHistory window:
; Paused threads: 0 of 0 (0 layers)
; Note also that the systray icon is still green because this thread will
; continue until it exits.
; Since there were no underlying threads, the script itself is paused, but this
; thread finishes executing first, so there are no paused threads:
; "Paused threads: 0"
; If I could press CTRL/h for "Hotkeys and their methods" window:
; Type Off? Level Running Name
; -------------------------------------------------------------------
; k-hook #p
; k-hook #q
; k-hook #r
; Note: "If I could press..." - I can only do that if I have MsgBox after
; "KeyHistory" line below. But MsgBox allows other threads to continue
; or interrupt, so using "x := 3" with breakpoint
; 1) Press the hotkey again ("#r")
KeyHistory
ListHotkeys
x := 3
; MsgBox 3 ; 2) KeyHistory should show:
; Paused threads: 0 of 1 (0 layers)
; The original "#r" thread
; Press CTRL/h for "Hotkeys and their methods" window:
; Type Off? Level Running Name
; -------------------------------------------------------------------
; k-hook #p
; k-hook #q
; k-hook 1 #r
return ; script is paused after "return"
}
Return to “AutoHotkey Development”
Users browsing this forum: No registered users and 41 guests