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

来源:互联网 发布:mac办公软件用什么 编辑:程序博客网 时间:2024/04/28 15:34

DELPHI代码

unit Unit1;interfaceuses  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);}


 

原创粉丝点击