August 14th, 2002, 06:29 PM
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!
August 14th, 2002, 06:37 PM
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.
August 14th, 2002, 06:58 PM
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?"
Just curious how a screensaver gets activated... As that is probably what I need to do.
August 14th, 2002, 07:02 PM
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 )
August 14th, 2002, 07:40 PM
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?
August 14th, 2002, 09:26 PM
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.
August 14th, 2002, 09:57 PM
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).
August 15th, 2002, 07:03 AM
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!
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!