获取系统输入闲置时间

 

 

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

 

你可能感兴趣的:(时间)