4

使用 Delphi Win32 (VCL) 我使用:

Application.OnMessage := MyAppMessage;

FireMonkey 中的等价物是什么?

我有一个例程需要捕获应用程序中的所有键盘和鼠标事件(在所有活动的表单控件上)并处理它们。

4

3 回答 3

6

FireMonkey 是跨平台的,可以在 Windows、Mac OSX、iOS 以及毫无疑问的许多其他平台上运行。因此,FireMonkey 不会公开任何 Windows 消息。

无论您习惯OnMessage在 VCL 中做什么,在 FireMonkey 中很可能都有相应的功能。确切的等价物在很大程度上取决于您的OnMessage处理程序试图实现的目标。

于 2011-11-08T21:52:41.867 回答
6

我不知道在 FireMonkey 中以与平台无关的方式在应用程序级别捕获鼠标和键盘事件的方法。从 Delphi XE 2 Update 2 开始,我认为这还没有实现。

但是,默认情况下,FireMonkey 表单会在控件之前获取所有 MouseDown 和 KeyDown 事件。

如果您简单地覆盖表单上的 MouseDown 和 KeyDown 事件,您将完成同样的事情。

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;

如果需要,您可以继续使用 MouseMove、MouseUp、MouseWheel、MouseLeave、KeyUp、DragEnter、DragOver、DragDrop 和 DragLeave。

于 2011-11-09T19:31:36.853 回答
0

这些答案对于暴露的事件来说很好,但对于其他晦涩的系统事件来说就更棘手了。在撰写本文时,此链接未得到答复:

捕获-usb-plug-unplug-events-in-firemonkey

但这将有助于解决一般问题。


我会将此作为评论而不是答案发布,但之前的答案不接受进一步的评论。

于 2012-11-23T01:18:43.673 回答