判断操作系统多久没有任何操作

function StopTime: integer; //返回没有键盘和鼠标事件的时间
var
  LInput: TLastInputInfo;
begin
  LInput.cbSize := SizeOf(TLastInputInfo);
  GetLastInputInfo(LInput);
  Result := (GetTickCount() - LInput.dwTime) div 1000;  // 微妙换成秒
end;

procedure TForm1.Timer1Timer(Sender: TObject);    // Timer 事件
begin
if StopTime >= 60 then
  Showmessage('用户已经1分钟没有动键盘鼠标了!');
end;
原文地址:https://www.cnblogs.com/bestlove/p/6734964.html