检测用户超过5分钟没有操作键盘或鼠标+函数

1.>>>5秒后提示,但只有一次============================================ 

procedure TForm1.Timer1Timer(Sender: TObject);
var  vLastInputInfo: TLastInputInfo;
begin  
vLastInputInfo.cbSize := SizeOf(vLastInputInfo); 
GetLastInputInfo(vLastInputInfo);
if GetTickCount - vLastInputInfo.dwTime > 5000 then
 begin
  timer1.Enabled:= false;  
  showmessage('超过5秒,用户未动鼠标!'); 
 end;
end;

 

得到停止操作时间

1. 定义过程

function LastInput: DWord;

 

2.解释过程

function TForm1.LastInput: DWord;
var
  LInput: TLastInputInfo;
begin
  LInput.cbSize := SizeOf(TLastInputInfo);
  GetLastInputInfo(LInput);
  Result := GetTickCount - LInput.dwTime;
end;

 

3.使用函数

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Caption:=IntToStr(LastInput);
end;

 

posted @ 2012-10-29 11:23  ftwsnow  阅读(386)  评论(0编辑  收藏  举报