Link to home
Start Free TrialLog in
Avatar of gertpienaar
gertpienaar

asked on

system mouse events

How do I capture system mouse events in Delphi4.
I only want to execute a process after a right mouse click anywhere on the screen.
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of inthe
inthe

credits:
cheers madshi ;-)
Avatar of gertpienaar

ASKER

Thanks a lot

Gert Pienaar
Barry.

I received an compiler error on the following line of code:
ourHook:=SetWindowsHookEx(WH_MOUSE,HookProc,HInstance,0);
I changed this to:
ourHook:=SetWindowsHookEx(WH_MOUSE,@HookProc,HInstance,0);
and it compiled OK.

I added the following code to an application:

function SetHook:Boolean; stdcall; external Hookdemo.dll';
function UnHookHook:Boolean; stdcall; external 'Hookdemo.dll';
function HookProc(Code:integer; wParam: Word; lParam: Longint):Longint; stdcall; external 'Hookdemo.dll';

and

procedure TForm1.Button2Click(Sender: TObject);
begin
  SetHook;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  UnhookHook;
end;

Nothing happened when running the program and clicking the mouse

I then loaded this application as a Host Application into the Hookdemo project to try and debug. When clicking on button2 the code in the Sethook function is executed, but when clicking the left mouse, the code in the HookProc is not execvuted and nothing happens.
Clicking Button3 executes the UnhookHook code.

Any suggestions why it doesn't execute the code in the HookProc.