System Idle time
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: System Idle time

  1. #1
    Join Date
    Nov 2000
    Location
    Bronx, NY
    Posts
    91

    System Idle time

    How does one get the system idle time?

    I want my application to minimize itself after a set amount of time of no mouse/keyboard movement.

    I don't think I can use OnIdle() because that works on my app's message queue. My app sends/posts messages every now and again. I want it to still do its job (sending/posting messages) in a minimized window after the user has not touch the keyboard or mouse, or any interface device for that matters.

    I am not sure what to look for in MSDN...

    any ideas appreciated!

    thanks!

  2. #2
    Join Date
    Aug 2001
    Location
    North Bend, WA
    Posts
    1,947
    One technique is to use a timer. Set the timer for the amount of time you want to use to wait to minimize. Catch the events that you want to have reset the timer. In the handlers for those events, kill the timer and reset it.

    In the timer handler, minimize the window.

  3. #3
    Join Date
    Nov 2000
    Location
    Bronx, NY
    Posts
    91
    That doesn't quite work the way I intended.

    My app can sit there non-minimized and stay non-minimized until there are no more input events from anywhere on the system, not just my app. This closely relates to a screensaver.

    Even if I process and reset a timer on every event my app does, I can't catch all the events when the mouse or a key is pressed when my app doesn't have the focus.

    So what I'm really asking is, "Is there an API to query the system how long ago was the last input processed for all windows/processes?"

    Thanks.

    Just curious how a screensaver gets activated... As that is probably what I need to do.

  4. #4
    You need to create an "idle tracker" DLL that hooks the mouse and keyboard. I think there's one in the Code Project ( www.codeproject.com )

  5. #5
    Join Date
    Nov 2000
    Location
    Bronx, NY
    Posts
    91
    I did some digging into MSDN.

    And found an article that specifies "Detecting Idle Time in Windows", Q96422

    Its pretty old and the technique involves polling interrupts or something!

    Surely there's got to be an easier way than to poll the hardware!

    Anybody have any easier ideas?

  6. #6
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658
    you can simply add OnIdle to your class and, when the idle counter gets to a certain limit, minimize.

    OnIdle is a well documented function, it may or may not be what you want. it is a very basic way to do what you want, and depending on how particular you are about how/when to idle (ie, paint messages & other background stuff is ok, but you want to see if the user physically moved the mouse or hit a key), then you want to do the hook method as suggested above.

    hth
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

  7. #7
    Join Date
    Nov 2000
    Location
    Bronx, NY
    Posts
    91
    Yes, it will look like i will have to use the hook method.

    But what i dont quite understand is, why it must be in a dll?
    Or is that legacy windows?

    After some more digging i found a function called, GetLastInputInfo() that will do what i want, but it only works for 2000 and later.

    i look forward to the day when 98 be phased out and all windows programmers will be happy again (at least relatively).

  8. #8
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658
    Here's how a global hook works:

    When a hook is grabbed, the code is injected into the actual application (or process, however you wanna think about it). It needs to be in dll format so that only the good hook code is injected (kind of the reason dll's are made in the first place, right?).

    Hope this makes sense!
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center