FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to detect mouse and keyboard not used for a time ?
Posts: 474
Joined: Sun Oct 30, 2005 06:37 AM
How to detect mouse and keyboard not used for a time ?
Posted: Thu Dec 13, 2007 02:32 AM

Hi,
As title, I want ,if over the setting time ,for example 10 minites ,then app do close app .
Thanks !
Shuming Wang

http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to detect mouse and keyboard not used for a time ?
Posted: Thu Dec 13, 2007 11:14 AM

Shuming,

Use a timer that checks a variable that holds the last time when the app was used. Keep such variable updated from your application.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
How to detect mouse and keyboard not used for a time ?
Posted: Thu Dec 13, 2007 12:23 PM

This is what I want too. And really very useful.

If in the main Window.Prg's Event Handler, we store the time in seconds whenever an event is handled, we can check thro a timer the difference between last event time and present time.

I am hesitatiing to touch the Window.Prg. If you guide Mr Antonio, we shall do it.

Anyway I have an api to find idle time for the entire system, but that is not what i want. I too want to know how long "my" application is idle.

Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
How to detect mouse and keyboard not used for a time ?
Posted: Thu Dec 13, 2007 12:30 PM
The code I thought of ...
dont know if this works for sure without adding any other complications

// Window.Prg
STATIC nLastEventTime	:= NIL
//
//
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS Window

	nLastEventTime	:= SECONDS()

RETURN  WndHandleEvent( Self, nMsg, nWParam, nLParam )
//
//
FUNCTION ExeIdleTime()
     // midnight correction is to be applied
RETURN iif ( nLastEventTime == NIL, 0, SECONDS()-nLastEventTime)
//

Something like this. Can you offer your guidance Mr Antonio ?
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
How to detect mouse and keyboard not used for a time ?
Posted: Thu Dec 13, 2007 12:36 PM
Here is my C function to know how long the entire system is idle
#include "hbapi.h"
#include <windows.h>
#include <winuser.h>

HB_FUNC( SYSTEM_IDLESECS )
{
   LASTINPUTINFO plii;
   DOUBLE dSecs ;

   plii.cbSize = sizeof( plii );
   if ( GetLastInputInfo( &plii ) ) 
       dSecs = ( DOUBLE ) ( GetTickCount() - plii.dwTime ) * 0.001 ;
   else dSecs = 0.0 ;

   hb_retnd(dSecs);
}
Regards



G. N. Rao.

Hyderabad, India
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to detect mouse and keyboard not used for a time ?
Posted: Thu Dec 13, 2007 01:23 PM

NageswaraRao,

The application may receive Windows msgs that don't come from the user

Thats why it may be better to check WM_COMMAND and similar msgs only

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
How to detect mouse and keyboard not used for a time ?
Posted: Thu Dec 13, 2007 01:30 PM

Can you guide me a little further mr. Antonio ?

Regards



G. N. Rao.

Hyderabad, India
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to detect mouse and keyboard not used for a time ?
Posted: Thu Dec 13, 2007 01:43 PM
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS Window 

   if nMsg == WM_COMMAND
      nLastEventTime := SECONDS()
   endif 

RETURN WndHandleEvent( Self, nMsg, nWParam, nLParam )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
How to detect mouse and keyboard not used for a time ?
Posted: Thu Dec 13, 2007 01:48 PM

Mr Antonio

Then do you advise me to add other events like WM_CHAR, WM_KEYDOWN, WM_LBUTTON ...... etc ( events that arise from keyboard and mouse ) to this IF condition ? May be a big list, but may be worth doing it if thats the way

Regards



G. N. Rao.

Hyderabad, India
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to detect mouse and keyboard not used for a time ?
Posted: Thu Dec 13, 2007 01:55 PM

Yes, use the msgs that you want to check

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion