1\我想做一个在鼠标,键盘20分钟以后没有动后提示的程序!那位能否给我源代码!
2\程序最小化在后面。不影响当前电脑操作。
找了三天资料还没有成功,满发给为给个源代码,谢谢!
2\程序最小化在后面。不影响当前电脑操作。
找了三天资料还没有成功,满发给为给个源代码,谢谢!
解决方案 »
- MIDAS是否已经淘汰?
- 关于建议加强管理,提高结贴率的建议
- stringGrid表格设置
- 向SARS宣战,为我们死去的白衣天使敬礼!!!
- 处学DELPHI者的紧急疑问~~求高手帮忙~~~
- Delphi 写的dll 怎么让vb调用。
- 如何为自己的软件做可以换的面板呢?就象Netscape 6.2 那种!
- 如何在delphi里实现断点再续
- 请教:delphi5跟vfp6在数据库处理上强的地方和弱的地方在哪里呢?
- 怎样从程序中获取一个已知文件的路径,并把路径保存在一个edit.text中,可有高手帮忙!
- 计算机编程类图书全部九成新大甩卖(西安)
- 请问rasWinGod 这个控件如何用!(在线等待)
监测系统多少时间没有用户输入
系统空闲时间检测 Idle我们知道,当用户超过一定的时间没有输入之后,Windows就会启动屏幕保护功能,那么在程序中如何做到这一点呢?就是说我如何检测到用户多久没有输入呢?大家知道,在Windows中有一个Hook技术,就是钩子,我们利用Hook技术,Hook键盘和鼠标,这样就可以知道用户有没有输入了!因此,我们可以修改Timer控件,继承下来就可以了:用法:if IdleTimer1.Snooze>6000 thenShowMessage('用户已经有6秒钟没有输入了!');///FileName:IdleTimer.Pasunit IdleTimer;interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ExtCtrls;typeTIdleTimer = class(TTimer)privatefunction GetSnooze: Longint;procedure SetSnooze(const Value: Longint);{ Private declarations }protected{ Protected declarations }public{ Public declarations }constructor Create(AOwner:TComponent);override;destructor Destroy;override;property Snooze:Longint read GetSnooze write SetSnooze;published{ Published declarations }end;procedure Register;implementationvarInstances:integer;ElapsedTime:Longint;whKeyBoard,whMouse:HHook;procedure Register;beginRegisterComponents('System', [TIdleTimer]);end;{ TIdleTimer }function MouseHookCallBack(Code:integer;Msg:lParam;MouseHook:wParam):DWORD;stdcall;beginif Code>=0 then ElapsedTime :=GetTickCount;Result := CallNextHookEx(whMouse,Code,Msg,MouseHook);end;function KeyBoardCallBack(Code:integer;Msg:word;KeyBoardHook:Longint):LongInt;stdcall;beginif Code>=0 then ElapsedTime :=GetTickCount;Result := CallNextHookEx(whKeyBoard,Code,Msg,KeyBoardHook);end;constructor TIdleTimer.Create(AOwner: TComponent);function GetModuleHandleFromInstance:THandle;vars:array[0..512] of char;beginGetModuleFileName(HInstance,s,SizeOf(s)-1);Result :=GetModuleHandle(s);end;begininherited Create(AOwner);Inc(Instances);if Instances =1 then beginElapsedTime :=GetTickCount;whMouse := SetWindowsHookEx(WH_MOUSE,@MouseHookCallback,GetModuleHandleFromInstance,0);whKeyBoard :=SetWindowsHookEx(WH_KEYBOARD,@KeyBoardCallBack,GetModuleHandleFromInstance,0);end;end;destructor TIdleTimer.Destroy;beginDec(Instances);if Instances =0 then beginUnhookWindowsHookEx(whKeyBoard);UnhookWindowsHookEx(whMouse);end;inherited;end;function TIdleTimer.GetSnooze: Longint;beginResult:= GetTickCount - ElapsedTime;end;procedure TIdleTimer.SetSnooze(const Value: Longint);beginElapsedTime := GetTickCount + Value;end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,IdleTimer, ExtCtrls, StdCtrls ;type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
IdleTimer1 : TIdleTimer ;
i : Integer ;implementation{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
IdleTimer1 := TIdleTimer.Create(Self) ;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
if IdleTimer1.Snooze > 1200000 then Caption := '20 Mins ' ;
Else
begin
Inc(i) ;
Caption := 'Living' + ' ' + IntToStr(i) ;
end ;
end;end.-------------------
// From my Friend ;unit IdleTimer;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;type
TIdleTimer = class(TTimer)
private
function GetSnooze: Longint;
procedure SetSnooze(const Value: Longint);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
property Snooze:Longint read GetSnooze write SetSnooze;
published
{ Published declarations }
end;procedure Register;implementationvar
Instances:integer;
ElapsedTime:Longint;
whKeyBoard,whMouse:HHook;procedure Register;
begin
RegisterComponents('System', [TIdleTimer]);
end;{ TIdleTimer }function MouseHookCallBack(Code:integer;Msg:lParam;MouseHook:wParam):DWORD;stdcall;
begin
if Code>=0 then ElapsedTime :=GetTickCount;
Result := CallNextHookEx(whMouse,Code,Msg,MouseHook);
end;function KeyBoardCallBack(Code:integer;Msg:word;KeyBoardHook:Longint):LongInt;stdcall;
begin
if Code>=0 then ElapsedTime :=GetTickCount;
Result := CallNextHookEx(whKeyBoard,Code,Msg,KeyBoardHook);
end;constructor TIdleTimer.Create(AOwner: TComponent);
function GetModuleHandleFromInstance:THandle;
var
s:array[0..512] of char;
begin
GetModuleFileName(HInstance,s,SizeOf(s)-1);
Result :=GetModuleHandle(s);
end;begin
inherited Create(AOwner);
Inc(Instances);
if Instances =1 then begin
ElapsedTime :=GetTickCount;
whMouse := SetWindowsHookEx(WH_MOUSE,@MouseHookCallback,GetModuleHandleFromInstance,0);
whKeyBoard :=SetWindowsHookEx(WH_KEYBOARD,@KeyBoardCallBack,GetModuleHandleFromInstance,0);
end;
end;destructor TIdleTimer.Destroy;
begin
Dec(Instances);
if Instances =0 then begin
UnhookWindowsHookEx(whKeyBoard);
UnhookWindowsHookEx(whMouse);
end;
inherited;
end;function TIdleTimer.GetSnooze: Longint;
begin
Result:= GetTickCount - ElapsedTime;
end;procedure TIdleTimer.SetSnooze(const Value: Longint);
begin
ElapsedTime := GetTickCount + Value;
end;end.
unit IdleTimer;
是不是新创建unit,然后拷贝代码即可
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
AppEvnts, ExtCtrls;type
TForm1 = class(TForm)
ApplicationEvents1: TApplicationEvents;
Timer1: TTimer;
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}
var LastUserActionTime: Cardinal = 0;procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if ((Msg.Message >= WM_KEYFIRST) and (Msg.Message <= WM_KEYLAST)) or
((Msg.Message >= WM_MOUSEFIRST) and (Msg.Message <= WM_MOUSELAST)) then
LastUserActionTime := GetTickCount;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
LastUserActionTime := GetTickCount;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
if GetTickCount - LastUserActionTime > 5 * 1000 then // 超过5秒用户不操作即关闭
Close;
end;end.
if GetTickCount - LastUserActionTime > 5 * 1000 then // 超过5秒用户不操作即关闭
Close;到底为什么
showmessage('用户已经有20分钟没有输入了'); //调试的时候将时间改小点
用于其他地方的请自行修改,
必要时还ApplicationEvents1Message中设Handled为false