怎样实现计算机处于闲置状态一段时间后自动运行某个程序?(类似屏幕保护)(100分)

  • 主题发起人 哈利波特
  • 开始时间

哈利波特

Unregistered / Unconfirmed
GUEST, unregistred user!
程序在后台运行,监视计算机状态,
如果在设定的时间内没有对计算机做任何操作则启动要运行的程序
 
写一个屏保程序不就可以了
 

不知道这样行不行。
引用一个计时器,按某一时间间隔去读取Windows的消息队列。
有消息则调用某个程序。
 
hook
//yanlei,yanleigis@21cn.com
var
Form1: TForm1;
hHook: integer;
Timesnum: integer;
implementation
{$R *.DFM}
const
Timescount = 300;
function HookProc(iCode: integer;
wParam: wParam;
lParam: lParam): LResult;
stdcall;
begin
Timesnum := 0;

Result := 0;
end;

function StartHook: Boolean;
begin
Result := False;
if hHook = 0 then
begin
hHook := SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);
if hHook > 0 then
begin
Result := True;
end;
end;
end;

procedure StopHook;
begin
if hHOok > 0 then
begin
UnHookWindowsHookEx(hHook);
hHook := 0;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
hHook := 0;
StartHook();
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
inc(Timesnum);
label1.Caption := floattostr(Timesnum);
if Timesnum > Timescount then
ShowMessage('ok');
end;

procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
stophook;
end;
 
getMessage()获取消息。
 
谢了!程序非常好啊!
 
我测试到上面的代码在WINXP下,一旦用Ctrl+Alt+Del之后,hook就失效了,不能检测到键
盘和鼠标的重新动作。请问是哪里出了问题呢?
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
顶部