[델파이로 만든 윈도우] 에서 작업중, 다른 프로그램을 사용할경우
기존 [처음에 사용하던윈도우] 입장에서는 idle time의 개념이 되는데.....
델파이에서 idle time을 체크해주는 함수는 없나요?
파워빌더의 경우 최상위 오브젝트인 어플리케이션오브젝트에 idle 이라는게 펑션이 있거든요
보다 더 정확하게 제 질문을 위해 파빌에서 help파일내용을 올립니다.
Idle PowerScript function
Description
Sets a timer so that PowerBuilder triggers an Application Idle event when there has been no user activity for a specified number of seconds.
Syntax
Idle ( n )
Argument Description
n The number of seconds of user inactivity allowed before PowerBuilder triggers an Application Idle event. A value of 0 terminates Idle detection.
이름 nilriri E-mail nilriri2@hotmail.com
제목 idle Timer
unit VIdle;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TVIdleTimer = class(TTimer)
private
{ Private-Deklarationen }
MaxIdle : integer;
FEnabled: Boolean;
function GetMaxIdleMinutes: integer;
procedure SetMaxIdleMinutes(Value: Integer);
procedure SetEnabled(Value: Boolean);
function GetLastActivity: TDateTime;
procedure SetLastActivity(const t: TDateTime);
function GetIdleTime: TDateTime;
function GetIdleMinutes: integer;
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
constructor Create(AOwner: TComponent);override;
destructor Destroy;override;
property LastActivity: TDateTime read GetLastActivity write SetLastActivity;
// last user activity.
property IdleTime: TDateTime read GetIdleTime;
// time passed since last user activity
property IdleMinutes: Integer read GetIdleMinutes;
// minutes passed since last user activity
published
{ Published-Deklarationen }
property Enabled: Boolean read FEnabled write SetEnabled default True;
property MaxIdleMinutes: Integer read GetMaxIdleMinutes write SetMaxIdleMinutes default 1;
// Enabled is the same as TTimer.Enabled, but it also controls
// monitoring user activity for ALL allocated TVIdleTimers. Use this
// for temporary interruptions of monitoring.
end;
procedure Register;
implementation
var
GLastActivity: TDateTime;
GInstanceCount: Integer;
whKeyboard,whMouse: HHook;
procedure GReset;
begin
GLastActivity := Now;
end;
{$IFDEF WIN32}
function MouseHookCallBack(Code: integer; Msg: WPARAM; MouseHook: LPARAM): LRESULT; stdcall;
{$ELSE}
function MouseHookCallBack(Code: integer; Msg: word; MouseHook: longint): longint; export;
{$ENDIF}
begin
if Code >= 0 then GReset;
Result := CallNextHookEx(whMouse,Code,Msg,MouseHook);
end;
{$IFDEF WIN32}
function KeyboardHookCallBack(Code: integer; Msg: WPARAM; KeyboardHook: LPARAM): LRESULT; stdcall;
{$ELSE}
function KeyboardHookCallBack(Code: integer; Msg: word; KeyboardHook: longint): longint; export;
{$ENDIF}
begin
if Code >= 0 then GReset;
Result := CallNextHookEx(whKeyboard,Code,Msg,KeyboardHook);
end;
function HookActive: Boolean;
begin
Result := whKeyboard <> 0;
end;
procedure CreateHooks;
function GetModuleHandleFromInstance: THandle;
var
s: array[0..512] of char;
begin
GetModuleFileName(hInstance,s,sizeof(s)-1);
Result := GetModuleHandle(s);
end;
begin
if not HookActive then begin
whMouse := SetWindowsHookEx(WH_MOUSE,MouseHookCallBack,
GetModuleHandleFromInstance,
{$IFDEF WIN32}GetCurrentThreadID{$ELSE}GetCurrentTask{$ENDIF});
whKeyboard := SetWindowsHookEx(WH_KEYBOARD,KeyboardHookCallBack,
GetModuleHandleFromInstance,
{$IFDEF WIN32}GetCurrentThreadID{$ELSE}GetCurrentTask{$ENDIF});
end;
end;
procedure RemoveHooks;
begin
if HookActive then
try
UnhookWindowsHookEx(whKeyboard);
UnhookWindowsHookEx(whMouse);
finally
whKeyboard := 0;
whMouse := 0;
end;
end;
constructor TVIdleTimer.Create;
begin
inherited;
CreateHooks;
if GInstanceCount = 0 then GReset;
MaxIdle := 1;
Inc(GInstanceCount);
end;
destructor TVIdleTimer.Destroy;
begin
Dec(GInstanceCount);
if GInstanceCount <= 0 then RemoveHooks;
inherited;
end;
procedure TVIdleTimer.SetMaxIdleMinutes(Value: Integer);
begin
MaxIdle := Value;
end;
function TVIdleTimer.GetMaxIdleMinutes : Integer;
begin
GetMaxIdleMinutes := MaxIdle;
end;
procedure TVIdleTimer.SetEnabled(Value: Boolean);
begin
FEnabled := Value;
inherited Enabled := Value;
if FEnabled then
CreateHooks
else
RemoveHooks;
end;
function TVIdleTimer.GetLastActivity: TDateTime;
begin
Result := GLastActivity;
end;
procedure TVIdleTimer.SetLastActivity(const t: TDateTime);
begin
GLastActivity := t;
end;
function TVIdleTimer.GetIdleTime: TDateTime;
begin
Result := Now - GLastActivity;
end;
function TVIdleTimer.GetIdleMinutes: Integer;
begin
Result := Trunc(IdleTime*1440.1);
end;
procedure Register;
begin
RegisterComponents('Verisoft', [TVIdleTimer]);
end;
initialization
GInstanceCount := 0;
whKeyboard := 0;
whMouse := 0;
end.
전에 자료실에 올렸던거 같은데..자료실이 안되네요..ㅡㅡ;
외국 어느 사이트에서 찾은건데요..
약간 수정했습니다.
컴파일해서 인스톨 하시구요..
MaxIdleMinutes에 시간입력하시구요.
enable := true로 놓으시고..
inteval에는..이벤트 발생 주기 밀리 세컨드로 입력하시고..
OnTimer 이벤트에서..
procedure TForm1.VIdleTimer1Timer(Sender: TObject);
begin
with VIdleTimer1 do
begin
Caption := DateTimeToStr(now);
if IdleMinutes >= MaxIdleMinutes then
begin
//여기에..지정한 idletime 이 되었을때 할일 기술..
Enabled := false;
showmessage(datetimetostr(VIdleTimer1.LastActivity));
end;
end;
end;