Есть код глобального хука в dll .
unit Hook;
interface
uses
System.SysUtils,
System.Classes,
Windows,
Messages;
type
tagKBDLLHOOKSTRUCT = packed record
vkCode: DWORD;
scanCode: DWORD;
flags: DWORD;
time: DWORD;
dwExtraInfo: Integer;
end;
KBDLLHOOKSTRUCT = tagKBDLLHOOKSTRUCT;
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
const
LLKHF_UP = $0080;
var
CurrentHook: HHook;
DestHandle: THandle;
Msg: cardinal;
function KeyboardProc(Code, wParam, lParam: Integer): Integer; stdcall;
procedure SetHook(aDestHandle: THandle; aMsg: cardinal); stdcall;
procedure UnHook; stdcall;
implementation
function KeyboardProc(Code, wParam, lParam: Integer): Integer; stdcall;
var
zKeyState: TKeyBoardState;
zChr: Char;
zCount: Integer;
zHookInfo : PKBDLLHOOKSTRUCT;
begin
Result := CallNextHookEx(CurrentHook, Code, wParam, lParam);
if Code <> HC_ACTION then Exit;
zHookInfo := Pointer(lParam);
if (zHookInfo^.flags And LLKHF_UP) <> 0 then
begin
GetKeyboardState(zKeyState);
zCount := ToAscii(zHookInfo.vkCode, zHookInfo.scanCode, zKeyState, @zChr, 0);
if zCount = 1 then
if DestHandle <> 0 then SendMessage(DestHandle, Msg, Ord(zChr), 0);
end;
end;
procedure SetHook(aDestHandle: THandle; aMsg: cardinal); stdcall;
begin
DestHandle := aDestHandle;
Msg := aMsg;
CurrentHook := SetWindowsHookEx(WH_KEYBOARD_LL, @KeyboardProc, HInstance, 0);
end;
procedure UnHook; stdcall;
begin
UnhookWindowshookEx(CurrentHook);
end;
end.
но в SendMessage в zChr возвращаются кракозябры. кириллицу не использую при наборе. первый символ проходит нормально , а остальные иероглифами.