MasterCluster.software Contact   About
Apps for Windows Source Code SQL Server Extensions  

DetectIdle component

Monitoring the Operating System and User Activity

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.


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
;

DescriptionTmcIdleStateGet Current Value
Workstation was either locked or unlockedisLockedWorkstationLocked
Screen Saver was either started or stoppedisScreenSaverScreenSaverRunning
Power was either suspended or resumedisPowerPowerSuspended
Application was entered either idle or active stateisAppIdleAppIdle
System was entered either idle or active stateisSysIdleSysIdle


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 using

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 to 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;

Get It From Here!

  1. Try the demo including the project source code and executable (220K download size).
  2. Read our Privacy Policy and Order Processing information.
  3. Buy the DetectIdle component source code using a safe payment processing service from Share*it!.


Copyright © 2003-2015 MasterCluster.com
Share |