使用Delphi Win32(VCL)我使用:
Application.OnMessage := MyAppMessage;
FireMonkey中的等效内容是什么?
我有一个例程需要捕获应用程序中的所有键盘和鼠标事件(在所有活动的表单控件上)并处理它们。
答案 0 :(得分:6)
FireMonkey是跨平台的,可以在Windows,Mac OSX,iOS上运行,并且在适当的时候无疑会有很多其他平台。因此,FireMonkey没有公开Windows消息。
无论是什么,你习惯于在VCL中使用OnMessage
,很可能在FireMonkey中具有等价物。究竟什么等价物很大程度上取决于你的OnMessage
处理程序试图实现的目标。
答案 1 :(得分:5)
我不知道在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。
答案 2 :(得分:0)
这些答案适用于暴露的事件,但对于其他模糊的系统事件,它更棘手。在撰写本文时,此链接未得到答复:
capturing-usb-plug-unplug-events-in-firemonkey
但它有助于解决一般问题。
我会将此作为评论而不是答案发布,但之前的答案并未接受进一步的评论。