Overview
|
The MCDetectIdle component allows application to monitor system activity such as:
- Screensaver start and stop
- Workstation lock and unlock
- Power suspend and resume
It also allows to monitor such user activity as mouse movements and keypresses within:
- Application that uses TMCDetectIdle component, and
- Whole system (available for Windows 2000 and later)
TMCDetectIdle Reference
See the Demo Project for examples on use.
|
DOWNLOAD TRIAL (220KB) |
|
Includes demo source and compiled files. The component source is available on purchase.
|
GET SOURCE CODE NOW! |
|
We use Share*it! service provider for secure payments processing.
You will receive a Download Link instantly right after you have made your order!
|
|
Methods and properties
function ScreenSaverEnabled: Boolean;
True when there is a Screen Saver enabled on the computer. Otherwise it is False.
function ScreenSaverTimeout: Integer;
Returns the Screen Saver's timeout (in seconds).
property MaxAppIdleTime: DWORD;
Sets or gets time (in milliseconds) since application considered idle.
When the Screen Saver is enabled on the computer, then its timeout value is used. Otherwise it is 300,000 ms (5 min) by default.
property MaxSysIdleTime: DWORD;
Sets or gets time (in milliseconds) since the whole system considered idle.
When the Screen Saver is enabled on the computer, then its timeout value is used. Otherwise it is 300,000 ms (5 min) by default.
property TimerEnabled: Boolean;
Starts or stops timer. The default property value is False (timer not started).
Note: Timer must be started in order to receive notifications by OnChange.
property TimerInterval: Integer;
Sets or gets time (in milliseconds) when the component checks the system state.
When Screen Saver is installed in system, then its timeout value is used. Otherwise it is 300,000 ms (5 min) by default.
property OnChange: TmcDetectIdleEvent;
Sets or gets a custom event handler.
The event handler receives States parameter that contains one or more of system modes that were changed.
Check the appropriate properties to determine the current value of the particular state.
type
TmcIdleState = (isLocked, isScreenSaver, isPower, isAppIdle, isSysIdle);
TmcIdleStates = set of TmcIdleState;
TmcDetectIdleEvent = procedure (Sender: TObject; const States: TmcIdleStates)
of object;
| Description | TmcIdleState | Get Current Value |
| Workstation was either locked or unlocked | isLocked | WorkstationLocked |
| Screen Saver was either started or stopped | isScreenSaver | ScreenSaverRunning |
| Power was either suspended or resumed | isPower | PowerSuspended |
| Application was entered either idle or active state | isAppIdle | AppIdle |
| System was entered either idle or active state | isSysIdle | SysIdle |
property PowerSuspended: Boolean;
True when computer enters the power saving mode, and False when power resumed.
function WorkstationLocked: Boolean;
True when the workstation console is locked, otherwise it is False.
function ScreenSaverRunning: Boolean;
True when the Screen Saver is running, otherwise it is False.
function StopScreenSaver: Boolean;
Stops the running Screen Saver.
Returns True when the screen saver was found running. Otherwise it is False (there was nothing to stop).
function AppIdle: Boolean;
True when MaxAppIdleTime is less than AppIdleTime.
Otherwise it is False.
function SysIdle: Boolean;
True when MaxSysIdleTime is less than SysIdleTime.
Otherwise it is False.
Note: This feature works only on Windows 2000 and later.
Thus SysIdle always returns False for earlier Windows versions (95/98/Me/WinNT).
function UserAway: Boolean;
True when either PowerSuspended, WorkstationLocked
or ScreenSaverRunning, AppIdle, or SysIdle is True.
Otherwise it is False.
function AppIdleTime: DWORD;
Returns time (in milliseconds) passed since the application received either mouse or keyboard input.
function SysIdleTime: DWORD;
Returns time (in milliseconds) passed since the whole system received either mouse or keyboard input.
Note: This feature only works on Windows 2000 and later.
Thus SysIdleTime always returns 0 for earlier Windows versions (95/98/Me/WinNT).
Examples
Start use
uses
mcDetectIdle;
...
TForm1 = class(TForm)
public
di: TmcDetectIdle;
...
procedure TForm1.FormCreate(Sender: TObject);
begin
di := TmcDetectIdle.Create(nil);
end;
After use
procedure TForm1.FormDestroy(Sender: TObject);
begin
di.Free;
end;
Respond events
There are two ways.
First, application may check the appropriate properties of TmcDetectIdle and make respective actions.
Second is to use timer and event handler of TmcDetectIdle.
To receive notifications, application has to specify
an event handler, a time interval (in milliseconds), and finally turn timer on:
TForm1 = class(TForm)
public
procedure evOnChange(Sender: TObject; const States: TmcIdleStates);
...
begin
di.OnChange := evOnChange;
di.TimerInterval := 6000; // default value is 3000
di.TimerEnabled := True;
end;
...
procedure TForm1.evOnChange(Sender: TObject; const States: TmcIdleStates);
begin
if isScreenSaver in States then // Screen Saver event
if di.ScreenSaverRunning then // Check if it's On or Off
end;
|