library KeyboardHook;
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
var
HookHandle: Cardinal = 0;
WindowHandle: Cardinal = 0;
hook:cardinal;
hwnd:cardinal;
hopenfilemap:cardinal=0;
p:pointer;
switch:boolean;
hcreatefilemap:cardinal=0;
oldproc:pointer;
function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM):
LRESULT; stdcall;
begin
//es ist ebenfalls möglich die Bearbeitung an eine Bedingung zu knüpfen
//it's possible to call CallNextHookEx conditional only.
case nCode < 0 of
TRUE: exit; //wenn code kleiner 0 wird nix gemacht
//if code smaller 0 nothing has to be done
FALSE:
begin
Showmessage(inttostr(wparam));
if (wParam<100)then Result := CallNextHookEx(HookHandle, nCode, 81, 81) //Wenn Tastaturcode kleiner 100, den Code auf 81 ändern
else Result := CallNextHookEx(HookHandle, nCode, wParam, lParam); //Wenn größer 100, die gedrückte Taste zurück geben
end;
end;
end;
function InstallHook(Hwnd: Cardinal): Boolean; stdcall;
begin
Result := False;
if HookHandle = 0 then begin
//Erstmal Hook installieren
//First install the hook
HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc,
HInstance, 0);
//Uebergebenes Fensterhandle sichern
//Save the given window
handle
WindowHandle := Hwnd;
Result := TRUE;
end;
end;
function UninstallHook: Boolean; stdcall;
begin
//Hook aus der Hookchain entfernen
//Uninstall hook from hook chain
Result := UnhookWindowsHookEx(HookHandle);
HookHandle := 0;
end;
exports
//Installations- und Deinstallationsroutine exportieren
//Export the installation and deinstallation routine
InstallHook,
UninstallHook;
end.