检测鼠标键盘多久没有活动(使用GetLastInputInfo API函数检测)
DELPHI代码
- 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.
VC代码
- DWORD GetInputAwayTime()
- {
- LASTINPUTINFO lpi;
- lpi.cbSize = sizeof(lpi);
- GetLastInputInfo(&lpi);
- return DWORD((GetTickCount()-lpi.dwTime)/1000);
- }
http://blog.csdn.net/cmdasm/article/details/10158601