大悟还俗

邮箱 key_ok@qq.com 我的收集 http://pan.baidu.com/share/home?uk=1177427271
  新随笔  :: 联系 :: 订阅 订阅  :: 管理

获取系统输入闲置时间

Posted on 2013-10-09 12:29  大悟还俗_2  阅读(136)  评论(0编辑  收藏  举报

 

 

delphi编写指定时间不动鼠标将系统锁定/以及在不动的情况下隐藏鼠标 
3秒种不动鼠标键盘看看效果。
GetLastInputInfo:获取闲置时间;
ShowCursor:设置鼠标状态

 

 

unit Unit1;
interface
uses
  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
  begin
    ShowCursor(False)//隐藏鼠标
    timer1.Enabled:= false;
    BlockInput(True);
    showmessage('超过3秒,已锁定!');
  end;
end;
end.
 
View Code