Solved

Systemwide Mousehook

Posted on 1997-10-12
1
402 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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now