unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
HookID: Cardinal;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
LButtonDownCounter,
LButtonUpCounter : integer;
RButtonDownCounter,
RButtonUpCounter : integer;
implementation
{$R *.dfm}
function MouseProc(nCode: Integer; wParam, lParam: Longint): Longint;
stdcall;
begin
case nCode < 0
of
True:
Result := CallNextHookEx(Form1.HookID, nCode, wParam, lParam)
else begin
case wParam
of
WM_LBUTTONDOWN :
begin
inc(LButtonDownCounter);
form1.label1.caption := IntToStr(LButtonDownCounter)
end;
WM_RBUTTONDOWN :
begin
inc(RButtonDownCounter);
form1.Label2.Caption := InttoStr(RButtonDownCounter)
end;
end;
{ of case }
Result := CallNextHookEx(Form1.HookID, nCode, wParam, lParam);
end
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
HookID := SetWindowsHookEx(WH_MOUSE, MouseProc, 0, GetCurrentThreadId());
LButtonDownCounter := 0;
LButtonUpCounter := 0;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if HookID <> 0
then
UnHookWindowsHookEx(HookID);
end;