function LastInput:DWord;
var
LInput:TLastInputInfo;
begin
LInput.cbSize:=sizeOf(TLastInputInfo);
GetLastInputInfo(LInput);
Result:=GetTickCount-LInput.dwTime;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
self.Caption:=Format('%d',[(LastInput)div 1000]);
end;