HanDs
管理员

[Delphi文章] 判断键盘鼠标是否移动 





学习中请遵循国家相关法律法规,黑客不作恶。没有网络安全就没有国家安全

本站需要登陆后才能查看

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
    hHook: integer;
    Timesnum: integer;
implementation

uses Unit2;
{$R *.DFM}
const
    Timescount = 60;

function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
begin
    Timesnum := 0;
   
    Result := 0;
end;

function StartHook: Boolean;
begin
    Result := False;
    if hHook = 0 then
    begin
        hHook := SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);
        if hHook > 0 then
        begin
            Result := True;
        end;
    end;
end;

procedure StopHook;
begin
    if hHOok > 0 then
    begin
        UnHookWindowsHookEx(hHook);
        hHook := 0;
    end;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
hHook := 0;
    StartHook();
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
stophook;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
    inc(Timesnum);
    label1.Caption := floattostr(Timesnum);
    if Timesnum > Timescount then
        ShowMessage('已经好久没动键盘和鼠标了!');
end;

 

end.


学习中请遵守法律法规,本网站内容均来自于互联网,本网站不负担法律责任
判断 键盘 鼠标 是否 移动
#1楼
发帖时间:2016-7-9   |   查看数:0   |   回复数:0
游客组
快速回复