有没有办法获取整个系统里鼠标和键盘有多久没动过了?解决方法

有没有办法获取整个系统里鼠标和键盘有多久没动过了?
有没有这样的API? Windows的屏幕保护程序是如何判断自己该啥时候出现的?

------解决方案--------------------
GetLastInputInfo
------解决方案--------------------
Delphi(Pascal) code

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  function BlockInput(fFreezeInput : boolean):DWord; stdcall; external 'user32.DLL';

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
var
  vLastInputInfo: TLastInputInfo;
begin
  vLastInputInfo.cbSize := SizeOf(vLastInputInfo);
  GetLastInputInfo(vLastInputInfo);
  if GetTickCount - vLastInputInfo.dwTime > 3000 then  //3秒钟
  begin
    timer1.Enabled:= false;
    BlockInput(True);
    showmessage('超过3秒,已锁定!');
  end;
end;

------解决方案--------------------
up.

但提醒一下,GetLastInputInfo在98下不适用。