Solved

Systemwide Mousehook

Posted on 1997-10-12
1
408 Views
Last Modified: 2010-04-03
Hi!

I tried to install a systemwide mousehook with
SetWindowsHookEx(WH_MOUSE, MouseHookCallBack, HInstance, 0)
inside a DLL. According to any articles I read about hooking this usually installs a systemwide mousehook, but it does not!

I use the DLL from my application, both coded with Delphi3. Inside the DLL all mouseevents are filtered and if there is the right one, a WM_USER message is posted to my application to inform it of the event.
But this only recognizes mouseevents on the application's form and not on the desktop or somewhere else.

What's wrong?
Is there any other way than using a DLL and hook procedures?

I tried to subclass the desktop window, but it does not work (as I read later). I think I declared everything as it should be (export and stdcall).

I saw several applications that are obviously able to receive systemwide events, but I did not manage.

Thanks in advance,
Harro
0
Comment
Question by:tier
1 Comment
 
LVL 1

Accepted Solution

by:
olmy earned 100 total points
ID: 1347326
Hi Tier

This keyboard hook is systemwide. It calls another program, but that part you can change.

library hookdll;
uses
  SysUtils,
  Classes,
  Windows,
  Messages;
var
  MyHook: HHOOK;

function MyHookProc(code: Integer; wparam: WPARAM; lparam: LPARAM): LRESULT stdcall;
var
  h: HWND;
begin
  Result := CallNextHookEx(MyHook, code, wparam, lparam);
  if (code = HC_ACTION) and ((lparam and $80000000) = 0) then begin
    // this is a keypress - tell caller
    h := FindWindow(nil, 'HookCaller');
    if h <> 0 then
      PostMessage(h, WM_APP, 0, 0);
  end;
end;

procedure Hook;
begin
  MyHook:= SetWindowsHookEx(WH_KEYBOARD, MyHookProc, hInstance, 0);
end;

procedure UnHook;
begin
  UnhookWindowsHookEx(MyHook);
end;

exports
  Hook, UnHook;

begin
end.


I Hope this helps :)

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question