1

What is the best way in Delphi 10 to get every mouseclick in my (windows-)application? I actually want to implement touch-sounds, but OnGesture only return gestures (surprise), so I want to go for any click. I don't want to capture every VCLs OnClick and am hoping for an overall hook/trigger/event

Wolfgang Bures
  • 509
  • 4
  • 12

1 Answers1

1

@David Heffernan is right, you can use the message event
if you want to get all event in others application, you should uses hook.
this is some function to do that by message(WM_LBUTTONDOWN WM_LBUTTONUP)
override application.OnMessage

application.OnMessage := yourOnMessage 

override WndProc(var message:TMessage);

procedure TForm1.WndProc(var message: TMessage);
begin
  inherited;
  if message.Msg = WM_LBUTTONDOWN then
    ShowMessage('down');

end;

only listen WM_LBUTTONDOWN

procedure Wmme(var message:TMessage);message WM_LBUTTONDOWN;
procedure TForm1.WndProc(var message: TMessage);
begin
  inherited;
  if message.Msg = WM_LBUTTONDOWN then
    ShowMessage('down');

end;

Para
  • 1,299
  • 4
  • 11
  • 1
    There are a few issues here: (1) You cannot "override" `Application.OnMessage`; you can assign your own handler, though. (2) Your second approach, `TForm1.WndProc`, will only detect clicks on `TForm1` itself -- not on any child control on this form, and not on any other form. (3) The third approach ... Well, here it is even very unclear what you mean. Probably you meant to use a message procedure instead of overriding `WndProc`, but forgot the old signature. Besides, your A could be improved by giving a concrete example of the first approach, and noting that it is probably better to use... – Andreas Rejbrand Feb 01 '21 at 13:20
  • ...a `TApplicationEvents`. Then different parts of the project need not compete for the same global variable. – Andreas Rejbrand Feb 01 '21 at 13:21