4
votes

With Delphi Win32 (VCL) I use:

Application.OnMessage := MyAppMessage;

What is the equivalent in FireMonkey?

I have a routine that needs to catch all the keyboard and mouse events in the application (on all the active form controls) and handle them.

3
Handling Windows messages won't be cross platform. What are you trying to accomplish?Marcus Adams
I edited your question to include what you're trying to do by copying your comment below and gave an answer.Marcus Adams

3 Answers

6
votes

FireMonkey is cross platform and runs on Windows, Mac OSX, iOS and no doubt many other platforms in due course. Therefore there are no Windows messages exposed by FireMonkey.

Whatever it is you are used to doing with OnMessage in the VCL most likely has an equivalent in FireMonkey. Exactly what that equivalent is depends very much on what your OnMessage handler is trying to achieve.

5
votes

I don't know of a way in FireMonkey to capture mouse and keyboard events at the application level in a platform agnostic way. I don't think that has been implemented yet, as of Delphi XE 2 Update 2.

However, by default FireMonkey forms get all of the MouseDown and KeyDown events before the controls do.

If you simply override the MouseDown and KeyDown events on your form, you'll accomplish the same thing.

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
  private
    { Private declarations }
  public
    { Public declarations }
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single); override;
    procedure KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState); override;
  end;

{ TForm1 }

procedure TForm1.KeyDown(var Key: Word; var KeyChar: System.WideChar;
  Shift: TShiftState);
begin
  // Do what you need to do here
  ShowMessage('Key Down');
  // Let it pass on to the form and control
  inherited;
end;

procedure TForm1.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Single);
begin
  // Do what you need to do here
  ShowMessage('Mouse Down');
  // Let it pass on to the form and control
  inherited;
end;

If you want, you can keep going with MouseMove, MouseUp, MouseWheel, MouseLeave, KeyUp, DragEnter, DragOver, DragDrop, and DragLeave.

0
votes

These answers are fine for exposed events, but for other obscure system events it's more tricky. At the time of writing this link isn't answered:

capturing-usb-plug-unplug-events-in-firemonkey

but it will help with solving the general problem.


I would have posted this as a comment not an answer, but the previous answers were not accepting further comments.