How to detect mouse and keyboard not used for a time ?
-
- Posts: 454
- Joined: Sun Oct 30, 2005 6:37 am
- Location: Guangzhou(Canton),China
How to detect mouse and keyboard not used for a time ?
Hi,
As title, I want ,if over the setting time ,for example 10 minites ,then app do close app .
Thanks !
Shuming Wang
As title, I want ,if over the setting time ,for example 10 minites ,then app do close app .
Thanks !
Shuming Wang
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
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.
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
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
The code I thought of ...
dont know if this works for sure without adding any other complications
Something like this. Can you offer your guidance Mr Antonio ?
dont know if this works for sure without adding any other complications
Code: Select all
// 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)
//
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Here is my C function to know how long the entire system is idle
Code: Select all
#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
G. N. Rao.
Hyderabad, India
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
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
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
Last edited by Antonio Linares on Thu Dec 13, 2007 1:31 pm, edited 1 time in total.
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Code: Select all
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS Window
if nMsg == WM_COMMAND
nLastEventTime := SECONDS()
endif
RETURN WndHandleEvent( Self, nMsg, nWParam, nLParam )
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact: