unit hooktest_main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
keybmsg='
KbHookMsg_MR';
type
TInstallHook =
function(Hwnd: THandle): Boolean;
stdcall;
TUninstallHook =
function: Boolean;
stdcall;
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private-Deklarationen }
protected
procedure WndProc(
var Message: TMessage);
override;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
WM_KEYBHOOKMSG :Cardinal = 0;
InstallHook: TInstallHook;
UninstallHook: TUninstallHook;
lib: Cardinal;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
lib := LoadLibrary('
hooktest_dll');
if lib <> INVALID_HANDLE_VALUE
then begin
InstallHook := GetProcAddress(lib, '
InstallHook');
UnInstallHook := GetProcAddress(lib, '
UninstallHook');
end;
// else ERROR
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
InstallHook(Self.Handle);
WM_KEYBHOOKMSG := getprop(Self.Handle,keybmsg);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
UninstallHook;
end;
procedure TForm1.WndProc(
var Message: TMessage);
begin
if (
Message.Msg=WM_KEYBHOOKMSG)
then
begin
SetForegroundWindow(Self.Handle);
ShowMessage(Chr(
Message.WParam));
end;
inherited;
end;
end.