有什么办法可以实现 比如10秒之内键盘和鼠标没有任何动作 就关闭软件 这个效果?10秒之内键盘和鼠标没有任何动作 这个如何监控??

解决方案 »

  1.   


    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      vLastInput: TLastInputInfo;
      Sec: Integer;
    begin
      vLastInput.cbSize := SizeOf(TLastInputInfo);
      GetLastInputInfo(vLastInput);
      Sec := (GetTickCount - vLastInput.dwTime) div 1000;
      if Sec >= 10 then Application.Terminate;
    end;
      

  2.   

    如果要获取系统的,就用老之的办法,本程序的就用bdmh的方法。也可以用HOOK
      

  3.   

    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;
      

  4.   

    function WindowsNoActionSec(ATargetSecond:Integer=0):Integer;
    var vLastInputInfo:TLastInputInfo;
    begin
      vLastInputInfo.cbSize := SizeOf(TLastInputInfo);
      GetLastInputInfo(vLastInputInfo);
      Result:=(GetTickCount-vLastInputInfo.dwTime) div 1000;
      if ATargetSecond>0 then
      begin
        if Result>=ATargetSecond then
          Result:=1
        else Result:=0;
      end;
    end;