读书人

有没有办法获取整个系统里鼠标和键盘有

发布时间: 2012-02-19 19:43:39 作者: rapoo

有没有办法获取整个系统里鼠标和键盘有多久没动过了?
有没有这样的API? Windows的屏幕保护程序是如何判断自己该啥时候出现的?

[解决办法]
GetLastInputInfo
[解决办法]

Delphi(Pascal) code
unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, ExtCtrls;type  TForm1 = class(TForm)    Timer1: TTimer;    procedure Timer1Timer(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end;  function BlockInput(fFreezeInput : boolean):DWord; stdcall; external 'user32.DLL';var  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);var  vLastInputInfo: TLastInputInfo;begin  vLastInputInfo.cbSize := SizeOf(vLastInputInfo);  GetLastInputInfo(vLastInputInfo);  if GetTickCount - vLastInputInfo.dwTime > 3000 then  //3秒钟  begin    timer1.Enabled:= false;    BlockInput(True);    showmessage('超过3秒,已锁定!');  end;end;
[解决办法]
up.

但提醒一下,GetLastInputInfo在98下不适用。

读书人网 >.NET

热点推荐