这是一个简单的钩子,看一下也许对你有些帮助,关键你要的是格式,这能满足你了
unit UnitDll;
interface
uses Windows;
const BUFFER_SIZE = 16 * 1024;
const HOOK_MEM_FILENAME = 'MEM_FILE';
const HOOK_MUTEX_NAME = 'MUTEX_NAME';
type
TShared = record
Keys: array[0..BUFFER_SIZE] of Char;
KeyCount: Integer;
end;
PShared = ^TShared;
var
MemFile, HookMutex: THandle;
hOldKeyHook: HHook;
Shared: PShared;
implementation
function KeyHookProc(iCode: Integer; wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
const
KeyPressMask = $80000000;
begin
if iCode < 0 then
Result := CallNextHookEx(hOldKeyHook,
iCode,
wParam,
lParam)
else begin
if ((lParam and KeyPressMask) = 0) then
begin
Shared^.Keys[Shared^.KeyCount] := Char(wParam and $00FF);
Inc(Shared^.KeyCount);
if Shared^.KeyCount >= BUFFER_SIZE - 1 then Shared^.KeyCount := 0;
end;
result:=0;
end;
end;
function EnableKeyHook: BOOL; export;
begin
Shared^.KeyCount := 0;
if hOldKeyHook = 0 then
begin
hOldKeyHook := SetWindowsHookEx(WH_KEYBOARD,
KeyHookProc,
HInstance,
0);
end;
Result := (hOldKeyHook <> 0);
end;
{撤消钩子过滤函数}
function DisableKeyHook: BOOL; export;
begin
if hOldKeyHook <> 0 then
begin
UnHookWindowsHookEx(hOldKeyHook);
hOldKeyHook := 0;
Shared^.KeyCount := 0;
end;
Result := (hOldKeyHook = 0);
end;
function GetKeyCount: Integer; export;
begin
Result := Shared^.KeyCount;
end;
function GetKey(index: Integer): Char; export;
begin
Result := Shared^.Keys[index];
end;
procedure ClearKeyString; export;
begin
Shared^.KeyCount := 0;
end;