Article View: comp.windows.ms.programmer
Article #3205Re: detecting user inactivity
From: Risto Lankinen
Date: Wed, 12 Jun 1991 08:59
Date: Wed, 12 Jun 1991 08:59
45 lines
2233 bytes
2233 bytes
bruceh@hpsciz.sc.hp.com (Bruce Haines) writes:
> Any ideas on how to sense user "inactivity". I'd like to set a
> timer that would go off if a user hasn't generated any keyboard/mouse
> input. Like whatever a screen saver app must do...?
Hi!
The 'idle-detecting' message loop may suit your case. That is, replace the
standard 'while( GetMessage() ) ... ' in the WinMain() with the following:
while(TRUE)
if( PeekMessage(&msg) )
{
// The queue contains messages - process them
// GetMessage() would automatically detect WM_QUIT, but here we
// must explicitly check for it.
if( msg.message==WM_QUIT ) break;
if( TranslateAccelerator(hWnd,hAcc,&msg) ) continue;
TranslateMessage( &msg );
DispatchMessage( &msg );
// You might want to save the last time a message was processed
dwLastMsgTime = GetTickCount();
}
else
{
// The queue is empty - user is doing nothing with *this* app
if( GetTickCount()-dwLastMsgTime > MSGTIMEDELTA )
{
// Do something funny
}
}
return msg.wParam;
Note, that the user might be doing something with *other* apps, so some
caution is necessary, if this will be used for a screen saver. Also
note, that the GetTickCount() eventually wraps around, if the computer
is kept powered for a long period of time.
Terveisin: Risto Lankinen
--
Risto Lankinen / product specialist ***************************************
Nokia Data Systems, Technology Dept * 2 3 *
THIS SPACE INTENTIONALLY LEFT BLANK * 2 +1 is PRIME! Now working on 2 -1 *
replies: risto@yj.data.nokia.fi ***************************************
Technical Details
Message-ID:
<1201@tuura.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!sics.se!fuug!tuura!ristoReferences:
<17190004@hpsciz.sc.hp.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!sics.se!fuug!tuura!risto From: risto@tuura.UUCP (Risto Lankinen) Newsgroups: comp.windows.ms.programmer Subject: Re: detecting user inactivity Message-ID: <1201@tuura.UUCP> Date: 12 Jun 91 08:59:35 GMT References: <17190004@hpsciz.sc.hp.com> Organization: Nokia Data Systems Oy Lines: 45