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.