Auto Time Out

T

tclancey

Hi all.

I have a requirement to Auto Time Out an application after a certain amount
on inactive time. If the user hasn't typed anything into the application,
and hasn't clicked any control the app will close all open forms, apart from
the main form and display the login.

I'm OK with most of this, but what is the best way to ensure each click or
key press is recorded? I don't want to put lines of code behind everything
for obvious reasons!

Cheers,
Tull.
 
G

Guest

Hey, Funny to see this posting because I was just about to ask a question
about auto time out. I would like to do the same thing in my application and
really have no idea how to do this, is there a good site i can refer to?
 
T

teslar91

Funny, I just ran across something this morning that might be useful.

application.AddMessageFilter: Use a message filter to prevent specific
events from being raised or to perform special operations for an event
before it is passed to an event handler. Message filters are unique to
a specific thread.

Google turns up some examples, including one from the MSDN which
filters out all left-clicks.

You could monitor mouse and keyboard events for the entire app with
this. A couple of tips:

1) Make sure your filter is fast and lean. It will be handling *lots*
of events, and you don't want to slow down your app.
2) Don't consider the mouse to have moved unless it moves more than
some threshold, like 8 pixels. Many mice tend to jitter a pixel or
two. They can also jitter *subpixel* amounts - which generates
extraneous MouseMove events that report the mouse hasn't moved (since
it can only report whole pixels).

For an easier alternative, you could use a timer that fires every
100ms or so, and checks the mouse position and keyboard state. This
could miss key presses if they occur between timer intervals. But
normally, you can't use an app for more than a few seconds without
moving the mouse anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top