![]() |
|
|
#1
|
|||
|
|||
|
Доброе время суток, спецы! Знаю что тема истерзана до дыр, но всетаки есть момент, который я не могу решить. Есть DL в котором я реализовал перехват клавиатуры. Пользовался стандартными методами создания HOOK'а. Вот проца хука и проца обработки хука, реализованной в DLL:
Код:
function KeyMsgProc(Code: integer; wParam: word;
lParam: LongInt): LongInt; stdcall;
var kn: array[0..50] of Char;
begin
if (Code = HC_ACTION) then
begin
GetKeyNameText(lParam, kn, SizeOf(kn));
CurrKey:= StrPas(kn);
CurrKey:= '|' + CurrKey + '|';
if (((lParam shr 16) and KF_UP) = 0) and (Pos(CurrKey, ShortC) = 0) then
begin
ShortC:= ShortC + '+' + CurrKey;
if ShortC[Length(ShortC)] = '+' then Delete(ShortC, Length(ShortC), 1);
if ShortC[1] = '+' then Delete(ShortC, 1, 1);
GenerateMsg(ShortC);
end
else
if (((lParam shr 16) and KF_UP) = KF_UP) then
begin
GetKeyNameText(lParam, kn, SizeOf(kn));
CurrKey:= StrPas(kn);
CurrKey:= '|' + CurrKey + '|';
Delete(ShortC, Pos(CurrKey, ShortC), Length(CurrKey));
CurrKey:= '';
if (ShortC <> '') then
begin
if (ShortC[Length(ShortC)] = '+') then Delete(ShortC, Length(ShortC), 1);
if (ShortC[1] = '+') then Delete(ShortC, 1, 1);
end;
end;
end;
Result:= CallNextHookEx(KHook, Code, wParam, lParam);
end;
procedure RunStopHook(State: boolean); stdcall; export;
begin
if (KHook <> 0) and State then exit;
if State then
begin
ShortC:= '';
KHook:= SetWindowsHookEx(WH_KEYBOARD, @KeyMsgProc, HInstance, 0);
end
else
begin
if KHook = 0 then exit;
UnHookWindowsHookEx(KHook);
KHook:= 0;
end;
end; |