|Windows with Delphi|
Windows API (94)
Windows Filesystem (229)
Windows Forms (527)
Windows Graphics (1092)
About this site
Links to us
Catching ALL mouse events
This article has not been rated yet. After reading, feel free to leave comments and rate it.
I tried to override the MouseDown() method in a subclass of TForm to get every event for a general handler.
I get only the events, when the user clicks somewhere on the form, where it has no controls. When the user clicks on a control, the message is handled by this control.
How can I get every MouseDown event in a form?
The Application.OnMessage event will see all mouse messages before they are delivered to the control under the mouse. You work at the API level there, however. If none of the controls needs to do special mouse processing just hook the same event to all OnMouse* events of interest.
The Sender parameter will tell you which control fired the handler.
Start with the example below:
You don't like the formatting? Check out SourceCoder then!
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure MyMouseEvent(var Msg: TMsg; var Handled: Boolean);
procedure TForm1.MyMouseEvent(var Msg: TMsg; var Handled: Boolean);
s : string;
case Msg.message of
wm_LButtonDown: s := 'left mouse down';
wm_LButtonUp: s := 'left mouse up';
wm_MouseMove: s := 'mouse move';
else s := '';
if s <> '' then
procedure TForm1.FormCreate(Sender: TObject);
Application.OnMessage := MyMouseEvent;