; Start conditions
; Minimum position change to trigger the recording event, in pixels
DetectionDelta := 5
; Period for movements detection, in ms (main loop)
MainLoopTime := 50
; Time without any movements to trigger the pause event, in milliseconds
; Always set it bigger than main loop time (>50 ms)
TimeoutBeforePause := 1500
CurrentTimeout := 0
; Asume that recording started
recActive := true
; Get mouse initial position
MouseGetPos, x1, y1
; Set timer for 50 ms (main loop)
SetTimer, Label_1, %MainLoopTime%
; No more auto-executed strings (after first "return" word).
return
;;;;;;;;;;;;;;;;;;;;;;;; General assignments ;;;;;;;;;;;;;;;;;;;;;;;;
; Suspend script by ScrollLock press,
; (for easy script termination when important keys in use).
; Pause timers and loops too.
ScrollLock::
{
Suspend
Pause
}
return
; Reflect user actions if any
; Pause recording (Ctrl + F1)
^F1::
recActive := false
return
; Reflect user actions if any
; Resume recording (Ctrl + F2)
^F2::
recActive := true
return
;;;;;;;;;;;;;;;;;;;;;;;; Main loop (mouse moves detection) ;;;;;;;;;;;;;;;;;;;;;;;;
Label_1:
MouseGetPos, x2, y2
; When left mouse down or
; distance exceeds threshold - resume recording and reset current timeout,
; otherwise continue to count timeout
if (GetKeyState("LButton", "P") or (Sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)) > DetectionDelta)) {
Gosub, Label_4 ; resume recording
CurrentTimeout = 0
x1 := x2
y1 := y2
} else {
CurrentTimeout += MainLoopTime
if (CurrentTimeout > TimeoutBeforePause) {
Gosub, Label_3 ; pause recording
CurrentTimeout = 0
}
}
return
;;;;;;;;;;;;;;;;;;;;;;;; Pause recording ;;;;;;;;;;;;;;;;;;;;;;;;
Label_3:
if (recActive) {
Send, {Ctrl Down}
Send, {F1 Down} ;
Sleep, 30 ; pause 30 ms to allow application to recognize the pressed state
Send, {F1 Up}
Send, {Ctrl Up}
recActive := false
}
return
;;;;;;;;;;;;;;;;;;;;;;;; Resume recording ;;;;;;;;;;;;;;;;;;;;;;;
Label_4:
if (not recActive) {
Send, {Ctrl Down}
Send, {F2 Down} ;
Sleep, 30 ; pause 30 ms to allow application to recognize the pressed state
Send, {F2 Up}
Send, {Ctrl Up}
recActive := true
}
return