Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect that the system is idle

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,485
9
38
Scotland
www.ml-consult.co.uk
Does anyone know how to detect that the user's system is idle -- that is, that there has been no keyboard or mouse activity for a given period?

I want a way of logging the user out of my application if they appear to be no longer sitting at their computer?

Thanks in advance.
Mike Lewis
Edinburgh, Scotland
 
You could set a timer, hook the keyboard and the mouse and reset the timer everytime there is input in the keyboard and/or mouse buffer.
Rum am Morgen vorkommt Kummer und Sorgen... Cheers !

Mr. Rum
 
Dr Mr Rum,

Thanks for the suggestion. However, I think it is little more complicated than that.

Hooking the keyboard and mouse would be fine within my own application. But I would also need a way of knowing if there was any activity in any other apps currently running. I'm looking for a way of seeing keyboard and mouse activity in other apps as well as mine.

The reason is that my own app displays confidential data, and the client is worried that, if a user goes to lunch while the app is still active, a colleague can come along and snoop at the data. On the other hand, if the user has my app minimised, and is bashing away at, say, a word processor, I don't my app to time out.

Perhaps I'm asking for the impossible.
Mike Lewis
Edinburgh, Scotland
 
You could place a low level hook, which captures input from all running threads (however, I do not think that this is supported on W95 and W98).
Rum am Morgen vorkommt Kummer und Sorgen... Cheers !

Mr. Rum
 
Check out SetWindowsHookEx, specify WH_KEYBOARD_LL and WH_MOUSE_LL....
Rum am Morgen vorkommt Kummer und Sorgen... Cheers !

Mr. Rum
 
Data about condition of processor keeps into regedit. If it can be usefull I will try to find this key
 
Actually this way not always works correctly...
If I did I would use something other
For C++ from MSDN:
while ( bDoingBackgroundProcessing )
{
MSG msg;
while ( ::peekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if ( !PumpMessage( ) )
{
bDoingBackgroundProcessing = FALSE;
::postQuitMessage( );
break;
}
}
// let MFC do its idle processing
LONG lIdle = 0;
while ( AfxGetApp()->OnIdle(lIdle++ ) )
;
// Perform some background processing here
// using another call to OnIdle
}

Low level detecting Idle Time in Windows described in Article ID: Q96422

I know that defenetly exist API to detect %usage of defined process if it can be usefull then I will try to find information about it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top