Is there a simpler way of doing this.

Thanks for any suggestions,
Joejr
Moderators: JRL, Dorian (MJT support)
Code: Select all
//<-- Dialog and OnEvent> Can be deleted
//Dialog for display purposes only
Dialog>Dialog1
Caption=User Active Monitor
Width=250
Height=74
Top=CENTER
Left=CENTER
Label= ,16,8,true
EndDialog>Dialog1
show>Dialog1
//Exit Sript if Dialog is Closed
OnEvent>WINDOW_NOTOPEN,User Active Monitor,2,Exit
//--> Dialog and OnEvent> Can be deleted
//Set inactive time - 3600 sec = 1 hour
Let>NoActiveTime=3600
//Count Seconds of inactivity
Let>NoActiveCounter=0
label>CheckIfUserActiveLoop
//Get Current Cursor Position
gcp>XPOS1,YPOS1
wait>1
//Check if Cursor has been mooved
gcp>XPOS2,YPOS2
//Check if Spacebar has been pressed
lib>User32,GetKeyState,SPACEBAR_STATE,32
//Start Counter
//If mouse position hasn't changed and spacebar hasn't been pressed
//in the last second
IF>{(%XPOS2%=%XPOS1%) AND (%YPOS2%=%YPOS1%) AND (%SPACEBAR_STATE%=0)}
add>NoActiveCounter,1
if>%NoActiveCounter%>%NoActiveTime%
//User has been inactive for more than an hour if NoActiveCounter is greater than NoActiveTime
mdl>You have been inactive for over an hour!
//Do something...
endif
//<-- Can be deleted
//Display how long user has been inactive in Dialog (Display purpose Only)
let>Dialog1.msLabel1=User Inactive for %NoActiveCounter% sec.
rda>Dialog1
//--> Can be deleted
ELSE
//User is active - Reset NoActiveCounter to 0
Let>NoActiveCounter=0
//Reset spacebar Key State if it was pressed
if>SPACEBAR_STATE=1
sen>SPACE
Press Backspace
endif
//<-- Can be deleted
//Display User is Active in Dialog (Display purpose Only)
let>Dialog1.msLabel1=User Active
rda>Dialog1
//--> Can be deleted
ENDIF
goto>CheckIfUserActiveLoop
srt>Exit