Best way to set up an idle timer
Devin Asay
devin_asay at byu.edu
Fri Aug 15 13:23:00 EDT 2003
Thanks for the great responses. I knew in my heart I really shouldn't
be using an idle handler, but couldn't figure out how to make a send ..
in message work without trapping every conceivable mouse and keyboard
event. Special thanks to Sarah and Edwin for putting me on to using a
front script to handle mouseMove and rawKeyDown messages. My HyperCard
roots were blinding me to this little gem of a concept--the ability to
insert a script into the front of all message paths. Anyway, here is
what I came up with. I included code that would provide a reasonable
user experience--it wouldn't just rudely log them out with no
explanation, and it gives a chance to re-enter a password if they typed
it wrong the first time.
Does this seem like a reasonable approach?:
========================start script sample==========================
-- 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
-- start timeout counter
insert the script of image "P&Rbg1.jpg" into front
send "logoutQuery" to stack "chinpr" in 5 * 60 seconds -- or whatever
time you want
end openStack
on logoutQuery
if the userPIN of this stack is not empty then -- i.e., if the user
is logged in
answer "A appropriate prompt here." with "Logout" or "Enter PIN..."
if it is "Enter PIN..." then -- (user chose to continue)
repeat forever -- or could put a limit here
ask information "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
send "logoutQuery" to stack "chinpr" in 5 * 60 seconds
end resetLogout
========================end script sample==========================
Devin Asay
Humanities Technology and Research Support Center
Brigham Young University
More information about the use-livecode
mailing list