Solved

Systemwide Mousehook

Posted on 1997-10-12
1
406 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to center only a line in richedit? 4 61
Working with hours 3 65
Delphi...Split view - idea? 1 88
Multi-layered image in FireMonkey 9 48
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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