截获键盘、鼠标消息
多长时间没人动就触发登陆窗口procedure TForm1.ApplicationEventsMessage(var Msg: tagMSG;
var Handled: Boolean);
begin
//如果已经定义主系统的Application的OnMessage事件则先调用;
//处理键盘、鼠标消息
if ((Msg.message >= WM_KEYFIRST) and (Msg.message <= WM_KEYLAST)) or
((Msg.message >= WM_MOUSEFIRST) and (Msg.message <= WM_MOUSELAST))then
LastActTime := now;
end;
procedure TForm1.TimerTimer(Sender: TObject) ;
begin
//如果键盘、鼠标在指定的时间内没有消息,调用处理事件
if SecondsBetween(now,LastActTime) > IdleTimeLimited then
begin
LastActTime := now;
ShowMessage('本程序未活动时间超过'+IntToStr(IdleTimeLimited)+'秒!');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
LastActTime := now;
IdleTimeLimited := 3;
Oclock := TTimer.Create(self);
Oclock.Enabled := True;
//设置时间控件的时间事件
Oclock.OnTimer := TimerTimer;
Application.OnMessage := ApplicationEventsMessage;
end;