BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

inactivity timeout

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics
View previous topic :: View next topic  
Author Message
Christopher
Guest





PostPosted: Sat Aug 20, 2005 7:16 am    Post subject: inactivity timeout Reply with quote



hi
Please advise on how to detect when there is no mouse nor keyboard input so
that i could close the application? Is there a function to do this?


Thanks
chris


Back to top
Peter Below (TeamB)
Guest





PostPosted: Sat Aug 20, 2005 12:31 pm    Post subject: Re: inactivity timeout Reply with quote



In article <4306d8c9$1 (AT) newsgroups (DOT) borland.com>, Christopher wrote:
Quote:
Please advise on how to detect when there is no mouse nor keyboard input so
that i could close the application? Is there a function to do this?

Not directly. What you have to do is monitor user input to your program and
record the time of last input. The use a timer with a suitable interval to
check this time of last input against the current time. If the difference is
larger than whatever inactivity timeout you want to use, do something.

You need three pieces of equipment here:

a) a "time of last activity" variable, field of your main form

FLastActive: TDateTime;

b) a timer that regularly checks the FLastActive variable against the
current time. Set it to an interval of, say 60000, and set its Active
property to true at design-time. The OnTimer event handler would be
something like this (timeout after 15 minutes):

If (FLastActive + EncodeTime( 0, 15, 0, 0 )) < Now Then
Close;

c) a handler for the Application.OnMessage event that updates the
FLastActive variable on each key or mouse message. The handler would
do something like this:

Case msg.Message of
WM_KEYFIRST..WM_KEYLAST, WM_MOUSEFIRST..WM_MOUSELAST:
FLastActive := Now;
End;

That's it.

For Win2K and XP there is an alternative: you can use the API function
GetLastInputInfo to query the OS about the last user input event.

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.