Solved

Systemwide Mousehook

Posted on 1997-10-12
1
409 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 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