Link to home
Start Free TrialLog in
Avatar of bluers
bluers

asked on

Idle event in VB

Hi experts,

Is there any way to perform an idle time checking in VB base on the value from INI files ? Each time the idle time exceeds, the login form will fire to the user.


Regards,
Bluers


Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Hi bluers,

You can try this to check the time difference:

Dim StartTime As Date
Dim StopTime As Date

StartTime = Now()

StopTime = StartTime + DateValue("00:05:00") 'hh:mm:ss , here add 5 minutes

In a Sub or Timer

Call CheckValue

Private Sub CheckValue
     DoEvents
     If Now > StopTime Then
          'Prompt Login Window

     End If
End Sub

'Hope will help.
Here is the code to read/write from an INI file:

http://www.vbcode.com/asp/showsn.asp?theID=1404

'Hope will help.
Hi bluers,

Sorry for the first post as it refer to compare Time values. By the way, the concept are similar:

Private Sub CheckValue(byVal myValue)
    DoEvents
    If myValueFromINI <> myValue Then
         'Prompt Login Window

    End If
End Sub

regards.
Avatar of bluers
bluers

ASKER

Hi ryancys,

But where should i put the timer object because my application is a MDI one ?
When you say idle time, do you mean when the user fails to move the mouse or press a key within a specified timeframe? If so then this is a bit more complicated.
Avatar of bluers

ASKER

Hi TimCottee,

Yes, thats what I mean and the timeframe comes from INI files ?
You can try the GetTickCount API in order to catch a time in milisecond between a certain processes.
You're trying to write a 'quiesce' function right? Ie if the user hasn't touched their app (mouse/keyboard) and it hasn't performed any processing for a certain amount of time, it requires a logon to use again?

The best way to do this is to use the GetLastInputInfo API call. This returns the time of the last input event. Unfortunately it's win2K only. Boo.

To do this for all platforms you need to hook the mouse and keyboard queues and handle messages as they come in.

I'll try and rustle up a code sample for you if you like
Ok, now I have done this before and it requires a bit of thinking about. You need to hook the windows keyboard and mouse messages and determine whether these are taking place inside the appropriate timeframe. The best way I have found of doing this is the vbalhook dll from http://vbaccelerator.com/codelib/hook/vbalhook.htm this will allow you to add a timer or if you want (and I did) use the ssubtmr timer also from vbaccelerator. You can then monitor the keyboard and mouse in the callback function(s) and reset the timer as necessary. When the timer event fires it is because no message has been processed within its interval and your form can be displayed.
ASKER CERTIFIED SOLUTION
Avatar of andyclap
andyclap
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
See this download in which I logoff an application after some time. You can reuse it to re-display the logon form instead of logging out.

http://www.universalthread.com/wconnect/wc.dll?FournierTransformation~2,54,Forum=21,28,1474
Hi bluers,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept andyclap's comment(s) as an answer.

bluers, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Per recommendation, force-accepted.

Netminder
CS Moderator