键盘钩子

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
const
//键盘掩码常量
_KeyPressMask=$80000000;
var
  Form1: TForm1;
  //定义钩子
  LogHook: HHook = 0;
implementation
{$R *.dfm}
//应用程序钩子
function LogProc(iCode: Integer; wParam: WPARAM;lParam: LPARAM): lresult; stdcall;export;
begin
     //处理钩子事件
      //Form1.WMhotkeyhandle(Msg);
    //if ((lParam and _KeyPressMask) = 0) and(GetKeyState(vk_control) <0) and (wParam = Ord('N'))then
    if ((lParam and _KeyPressMask) = 0) and(GetKeyState(vk_control) <0) and(GetKeyState(VK_MENU) <0)
     and (wParam = Ord('X'))then
     begin
       // showmessage('xxxxxvvvvvvccccccc');
       Form1.Close;
    end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
      Form1.BorderStyle:=bsNone;
       Form1.WindowState:=wsMaximized;
      Form1.Height:=screen.Height;
      Form1.Width:=screen.Width;
          Label1.Top:=0;
          Label1.Left:=0;
      Label1.Height:=Form1.Height;
      Label1.Width:=Form1.Width;
       if LogHook = 0 then
       //挂钩
    LogHook := SetWindowsHookEx(WH_KEYBOARD, LogProc, HInstance, 0);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if LogHook <> 0 then
      begin
        //卸钩
        UnhookWindowsHookEx(LogHook);
        LogHook := 0;
      end;
end;
end.


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值