The three OnEvent> parameters needed for a custom event handler are the "event parameter" which I have named "srtTestForMouseMovement". The "extra parameter" which I have named "vDeltaMouse". Lastly the "trigger parameter" which I have called "srtRunThisWhenMouseMoves"
While the rest of the script is processing, Macro Scheduler runs the "event parameter" subroutine up to 64 times per second waiting for the variable name defined in "extra parameter" to have a text value "TRUE". When "extra parameter" variable value becomes equal to the text "TRUE" the "trigger parameter" subroutine is run.
In this case "srtTestForMouseMovement" checks the location of the mouse cursor approximately every 0.015 seconds and compares the X and Y coordinates to the previous X and Y coordinates, if either of the coordinates change, the mouse must be moving and the variable "vDeltaMouse" is set to the text value "TRUE". When "vDeltaMouse" becomes "TRUE", the "srtRunThisWhenMouseMoves" subroutine is executed.
Don't forget that the trigger parameter subroutine is an ideal place to set the extra parameter variable to something other than the text "TRUE". The variable value needs to be reset otherwise the trigger parameter subroutine will never stop executing. In the script below notice the first line of the "srtRunThisWhenMouseMoves" subroutine sets the variable "vDeltaMouse" to the text value "FALSE".
Code: Select all
GetCursorPos>vCurXold,vCurYold
Let>vDeltaMouse=FALSE
Message>
OnEvent>Custom,srtTestForMouseMovement,vDeltaMouse,srtRunThisWhenMouseMoves
SRT>srtTestForMouseMovement
GetCursorPos>vCurXnew,vCurYnew
If>{(%vCurXold%-%vCurXnew%<>0)or(%vCurYold%-%vCurYnew%<>0)}
Let>vDeltaMouse=TRUE
EndIf
END>srtTestForMouseMovement
SRT>srtRunThisWhenMouseMoves
Let>vDeltaMouse=FALSE
GetCursorPos>vCurXold,vCurYold
SetControlText>Macro Scheduler Message,TMemo,1,Mouse cursor IS moving
Wait>0.2
END>srtRunThisWhenMouseMoves
Label>Loop
If>vDeltaMouse=FALSE
SetControlText>Macro Scheduler Message,TMemo,1,Mouse cursor is NOT moving
Let>vDeltaMouse=STATIONARY
EndIf
IfWindowOpen>Macro Scheduler Message
Else
Exit>0
EndIf
Wait>0.1
Goto>Loop