Waiting for useraction

Hi everybody!

I didnt deal with this up till now. So if you could give me some “startup” hints it would be nice.

I would like to have something like a forced “logout” from my App if the user does nothing for a defined time (means: no mouse movement, no keystroke) The idea of using a timer is clear but how can i “listen” keyboard and mouse for doin nothing?

Thanks for your answers


The Keydown event in controls should do

For watching the mouse, use another, short-period timer (a second or so) and watch System.MouseX and System.MouseY. If they change, then reset the long-period logoff timer. Heck, it could even be once a minute. It’s very unlikely the mouse will return to exactly the same location, so any movement will be noticed.

i am trying this but don’t know how to set this up. a sample would be nice.

can i put the 2 timer in the main menu which is open all the time??
how do i reset the long period time??
do i need to define 2 variable for the prevX and prevY ??
if i am on another window, will the System.MouseX and System.MouseY be able to update the PrevX and PrevY on the main menu window??

Why not just a long period timer (what ever the max idle time you want)

Everytime you get a KEYDOWN event or a MOUSE event, reset the timer…

let me try

just try dave idea and it work.

i want to do be able to do is set an indicator in the database something like MaintenanceModeYN and when i set this, the application on the other machine will check this indicator every 1 or 2 minutes and give user a message asking to save the record and close the application. And if anyone trying to login with MaintenanceModeYN set to true, message will tell them that can’t login and have to wait.

Once maintenance work is done, the indicator is set back to false, people can start login and use the application again.

I suggested a second timer just so you wouldn’t have to put code in every mousemove event. Just to simplify things a bit. Depending on how many controls are on your window, it may not matter much. You still have to implement every keydown event anyway.

tim, can’t i just put the code in the MouseMove event on the Mainmenu window??

I didn’t think that would work, but it looks like it does. Sorry for the noise.

is ok… always good to have suggestion or alternative

Thanks everybody - thats what im calling “a little startup - hint” :wink: thats what i needed!!!