Best way to set up an idle timer - The prize goes to...

Robert Brenstein rjb at rz.uni-potsdam.de
Mon Aug 18 17:55:00 EDT 2003


>==============start script sample (line wrapping alert!)============
>-- first of all, put into an otherwise unused script:
>on mouseMove
>   send "resetLogout" to stack "chinpr"
>   pass mouseMove
>end mouseMove
>
>on rawKeyDown
>   send "resetLogout" to stack "chinpr"
>   pass rawKeyDown
>end rawKeyDown
>
>-- then I put into my stack script:
>on openStack
>   -- my other openStack junk here
>   insert the script of image "P&Rbg1.jpg" of stack "chinpr" into 
>front -- this handles mouseMove and rawKeyDown
>   resetLogout -- start the logout countdown
>end openStack
>
>on logoutQuery
>   if the userPIN of this stack is not empty then
>     beep
>     answer "An appropriate prompt here." with "Logout" or "Enter PIN..."
>     if it is "Enter PIN..." then -- (user chose to continue)
>       repeat
>         ask "Enter your PIN to continue the test."
>         if it is the userPIN of this stack then
>           resetLogout
>           exit repeat
>         else
>           answer information "Incorrect PIN. Try Again or Logout?" 
>with "Logout" or "Try Again"
>           if it is "Logout" then
>             go card "menu" of stack "chinpr"
>             logout
>             exit repeat
>           end if
>         end if
>       end repeat
>       exit logoutquery
>     else if it is "Logout" then -- (user chose to log out)
>       go card "menu" of stack "chinpr"
>       logout
>       exit logoutQuery
>     end if
>   end if
>end logoutQuery
>
>on resetLogout
>   --  cancel item 1 of last line of the pendingMessages
>   put the pendingMessages into pndgMsgs
>   repeat for each line thisMsg in pndgMsgs
>     if item 3 of thisMsg contains "logoutQuery" then cancel item 1 of thisMsg
>   end repeat
>   send "logoutQuery" to stack "chinpr" in 5 * 60 seconds -- or 
>whatever time period you want
>end resetLogout
>
>========================end script sample==========================
>
>Devin Asay
>Humanities Technology and Research Support Center
>Brigham Young University

I am coming late to this thread. While the above solution works, 
there is an alternative approach that eliminates the need to deal 
with sending and fiddling with pending messages, assuming that you 
are after catching user doing nothing in the program because of 
leaving or talking on the phone or going to get coffee. The key 
element is to store a timestamp (easiest to use is the seconds 
function) of last activity in parallel to userPIN. The resetLogout 
function would then check whether the difference between current 
seconds and the last stored seconds is more than timeout threshold. 
If yes, it would call logoutQuery alse reset the timestamp to current 
seconds.

Of course, a big functional difference is that with sending, you can 
display a logout dialog when the timeout threshold actually expires. 
Without sending, you would need to modify the dialog to say something 
like: due to xx minutes of inactivity you were logged out; enter your 
PIN to log in or click exit to leave the program. The user does not 
need to know that you are actually bluffing and will log him out only 
now.

The plus of this solution is that it is not affected by computer sleeping.

RObert



More information about the use-livecode mailing list