检测鼠标键盘多久没有活动

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
//typedef struct tagLASTINPUTINFO {
  //UINT cbSize;
 // DWORD dwTime;
// LASTINPUTINFO, *PLASTINPUTINFO;


type
   LASTINPUTINFO = record
   cbSize:UINT;
   dwTime:DWORD;
end;
var
  Form1: TForm1;

implementation

{$R *.dfm}



function GetInputAwayTime():DWORD;
var
  lpi:TLastInputInfo;
begin
  lpi.cbSize := sizeof(lpi);
  GetLastInputInfo(lpi);
  Result := Round((GetTickCount()-lpi.dwTime)/1000);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
   Caption := IntToStr(GetInputAwayTime)
end;

end.

你可能感兴趣的:(检测鼠标键盘多久没有活动)