CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 1999
    Location
    India, West Bengal
    Posts
    36

    Idle time detect

    How can I check if the application (VB App only) has been inactive for a certain time (more than 1 minute - because the timer control max value if just abouve i minute).

    Is there any API call by which i can keep reading time for say more than 20 minutes and also find if there is no mouse movement for that time. Then i want to fire a idle time check and run a routine on it.

    Please help.
    Thanx in advance
    Nilanjan


  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Idle time detect

    You could download the EventVB.OCX control from http://www.merrioncomputing.com/Download/index.htm and drop it on to your application main form.

    In the form load:

    private Sub Form_Load()

    VBEventWindow1.hWnd = me.hWnd

    End Sub




    and then in the events of that control:

    private Sub VBEventWindow1_WindowMessageFired(byval msg as EventVB.WindowMessages, byval wParam as Long, byval lParam as Long, Cancel as Boolean, ProcRet as Long)


    If msg = WM_ENTERIDLE then
    '\\ Thread isn't doing anything...
    End If

    End Sub




    You can then use this to tell you when your application is idle.

    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: Idle time detect

    Actually you can still work with the VB Timer like this:


    option Explicit

    dim nMaxIdle as Integer ' how long to wait before triggering the idle function
    dim nCurIdle as Integer ' cur idle time

    private Sub Form_Load()
    ' init idle counters
    nMaxIdle = 20 '20 minutes
    nCurIdle = 0 ' 0

    ' init timer
    Timer1.Enabled = false
    Timer1.Interval = 60 * 1000 ' 60secs = 1min

    ' start timer
    Timer1.Enabled = true
    End Sub

    private Sub Timer1_Timer()
    ' increment timer
    nCurIdle = nCurIdle + 1
    if (nCurIdle = nMaxIdle) then
    ' idle time reached - stop timer
    Timer1.Enabled = false

    ' trigger function
    Call TriggerIdle()

    nCurIdle = 0 ' reset counter
    Timer1.Enabled = true ' re-enable timer
    end if
    End Sub

    private Sub TriggerIdle()
    ' trigger the idle procedure
    End Sub

    private Sub ResetIdle()
    ' proc to reset the idle time
    Timer1.Enabled = false
    nCurIdle = 0
    Timer1.Enabled = true
    End Sub

    private Sub Form_KeyPress(KeyAscii as Integer)
    ' whenever there is a keypress - reset idle counter
    Call ResetIdle()
    End Sub

    private Sub ConnectToDB()
    ' disable timer
    Timer1.Enabled = false
    nCurIdle = 0

    ' do your processing here
    ...

    ' re-enable timer
    Timer1.Enabled = true
    End Sub




    Of course, this will require you to reset the Idle Counter manually everytime you form is used. For example above, I trapped the KeyPress() event and call the ResetIdle() function to reset my idle time. Or you can follow the example in ConnectToDB() function which disable the Idle Timer until the funcion finishes.

    The code above have not been tested (I used the same theory in my old program but don't have it handy, so I came up with the code above). You might wanna play with it more

    -Cool Bizs

    Good Luck,
    -Cool Bizs

  4. #4
    Join Date
    Aug 1999
    Location
    India, West Bengal
    Posts
    36

    Re: Idle time detect

    Thankx guys. Both the posts were helpful.

    Nilanjan


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured