unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  AppEvnts, ExtCtrls;type
  TForm1 = class(TForm)
    ApplicationEvents1: TApplicationEvents;
    Timer1: TTimer;
    procedure ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.DFM}
var LastUserActionTime: Cardinal = 0;procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
begin
  if ((Msg.Message >= WM_KEYFIRST) and (Msg.Message <= WM_KEYLAST)) or
     ((Msg.Message >= WM_MOUSEFIRST) and (Msg.Message <= WM_MOUSELAST)) then
    LastUserActionTime := GetTickCount;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
  LastUserActionTime := GetTickCount;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if GetTickCount - LastUserActionTime > 60 * 1000 then  
    showmessage('您一分钟没有移动鼠标键盘');
end;end

解决方案 »

  1.   

    它只是检测你线程处理的消息,就是说只有当此程序收到windows消息的时候才会触发这个事件,注意是此程序,不是系统。假若你的程序不是active状态,那么它是得不到鼠标键盘消息的。
    用鼠标在你的form上动,看看效果。
      

  2.   

    那我想获取30分钟鼠标,键盘不动的消息该如何做!
    上个帖子我已经发了,里面的idletimer控件也没有调试成功,到底如何解决。钩子不会写,大家能否发个源代码给我!感激不尽![email protected]