unit KeyboardF5;
type
IKeyboardF5 =
interface(IInterface)
function GetF5Variable: Integer;
procedure SetF5Variable(AValue: Integer);
end
//---------
library jtdll;
uses
Windows, Dialogs, Messages, KeyboardF5;
var
HookHandle: Cardinal;
KeyboardF5: IKeyboardF5;
function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT;
stdcall;
begin
Result:=CallNextHookEx(HookHandle, nCode, wParam, lParam);
case nCode<0
of
True:
Exit;
False:
begin
if (wParam=VK_F5)
and Assigned(KeyboardF5)
then
KeyboardF5.SetF5Variable(1);
end;
end;
end;
function InstallHook(AKeyboardF5: IKeyboardF5): Boolean;
stdcall;
begin
Result := (HookHandle = 0);
if Result
then
begin
HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc, HInstance, 0);
KeyboardF5 := AKeyboardF5;
end;
end;
function UninstallHook: Boolean;
stdcall;
begin
Result := UnhookWindowsHookEx(HookHandle);
HookHandle := 0;
KeyboardF5 :=
nil;
end;
exports
InstallHook,
UninstallHook;
end.
//---------
unit Form1;
uses
{...}
KeyboardF5;
type
TForm1 =
class(TForm, IKeyboardF5)
{...}
private
xyz: Integer;
function GetF5Variable: Integer;
procedure SetF5Variable(AValue: Integer);
end;
implementation
function TForm1.GetF5Variable: Integer;
begin
Result := xyz;
end;
procedure TForm1.SetF5Variable(AValue: Integer);
begin
xyz := AValue;
end;
procedure TForm1.Show(Sender: TObject);
begin
InstallHook(Self);
end;
procedure TForm1.Close(Sender: TObject);
begin
UnInstallHook;
end;