首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

有没有办法获取整个系统里鼠标和键盘有多久没动过了?解决方法

2012-02-19 
有没有办法获取整个系统里鼠标和键盘有多久没动过了?有没有这样的API? Windows的屏幕保护程序是如何判断自

有没有办法获取整个系统里鼠标和键盘有多久没动过了?
有没有这样的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下不适用。

热点排行
Bad Request.