unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
WM_KeyLogMessage = WM_USER + 23;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
procedure OnMyMessage(
var Msg: TMessage);
message WM_KeyLogMessage;
public
{ Public-Deklarationen }
end;
TInstallHook =
function(Hwnd: THandle): Boolean;
stdcall;
TUninstallHook =
function: Boolean;
stdcall;
var
Form1: TForm1;
InstallHook: TInstallHook;
UninstallHook: TUninstallHook;
lib: Cardinal;
implementation
{$R *.dfm}
procedure TForm1.OnMyMessage(
var Msg:TMessage);
begin
memo1.Lines.Add(inttostr(msg.lparam));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
lib := LoadLibrary('
keyboardhook.dll');
if lib <> INVALID_HANDLE_VALUE
then begin
InstallHook := GetProcAddress(lib, '
InstallHook');
UnInstallHook := GetProcAddress(lib, '
UninstallHook');
end;
// else ERROR
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
freelibrary(lib);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
installhook(self.Handle);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
uninstallhook;
end;
end.