Results 1 to 7 of 7

Thread: How Can I Tell If My Program Is Idling ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    219

    Post

    How Can I Tell If My Program Is Idling ?

  2. #2
    Junior Member
    Join Date
    Oct 1999
    Location
    Rijswijk, Holland
    Posts
    25

    Post

    Please be more clear.

    Ingrid.

  3. #3
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301

    Post

    Its only idle when waiting for events after processing any called functions etc

    You should know what functions you have called. If you need to know that a function has finished set a global flag.

    eg.

    gvfunc_finished=true



  4. #4
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    Here is I deal with that: ( I have to make my projects password-protected after it went to Idle)

    Public IdleCount as Integer

    'In frmMain

    Timer1.Interval = 60000 ' About a minute

    'In Timer1

    Sub Timer1_timer()
    IdleCount=IdleCount+1

    if IdelCount>=10 then ' I send my APP in Idel Mode after 10 min
    call IdelMode()
    End If
    Edn Sub
    'But in each and every Active event you must zero IdleCounter = 0 ( every clicks, gotFocus, MouseMove)


    My method is far away from a piece of art, but it works.



  5. #5
    Guest

    Post

    i think u should better use an API Callback, because the SUB TIMER1 will only be executed if you're programm is not idle.....

  6. #6
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Post

    I think it depends on how you are defining "idle". If you mean that the user hasn't touched it for a while, then you can simply monitor keyboard and mouse events associated with your program using APIs or probably even VB's keypress and mousemove events. If there has been no activity for a certain period, then initiate your password form.

    You can do this with a timer and a global variable that tracks the last time the user pressed a key or moved the mouse on your form. To use this sample, create a form with a timer control (Timer1). Then add the following code to the form's code module.
    Code:
    Option Explicit
    
    Private Const MaxSeconds As Single = 10    'Number of seconds allowed for inactivity
    Private LastUse As Single               'Variable stores time prog was last used
    
    Private Sub Form_Load()
    
        Timer1.Interval = 100
        
        LastUse = Timer
        
    End Sub
    
    Private Sub Form_KeyPress(KeyAscii As Integer)
        
        LastUse = Timer
    
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        LastUse = Timer
    
    End Sub
    
    Private Sub Timer1_Timer()
    
        'Here you check to see if the user hasn't used your program for
        'a certain time.  If the number of seconds specified in the constant
        'MaxSeconds has elapsed since the user touched your program, then
        'the password box comes up.  Don't forget to reset x here, too!
        
        If Timer > LastUse + MaxSeconds Then
            InputBox "Enter Password:"
            LastUse = Timer
        End If
        
    End Sub
    I hope that at least gives you an idea of one way to approach the problem.

    Good luck,

    ~seaweed

    [This message has been edited by seaweed (edited 02-18-2000).]

  7. #7
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    Seaweed!
    Your idea is just great, I gonna dupm mine.

    The only thing, You realy don't need a Timer,
    This will do:
    'In any Active event

    if Now()> LastUse + MaxSeconds then
    'Ask for password
    else
    'Reset LastUse
    LastUse=Now()
    end if
    Don't you think so"

    And you should not use timer()
    as soon as it resets to 0 at midnight.

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