使用Delphi Win32(VCL)我使用:
Application.OnMessage := MyAppMessage;
Run Code Online (Sandbox Code Playgroud)
FireMonkey中的等价物是什么?
我有一个例程,需要捕获应用程序中的所有键盘和鼠标事件(在所有活动的窗体控件上)并处理它们.
FireMonkey是跨平台的,可以在Windows,Mac OSX,iOS上运行,并且在适当的时候无疑会有很多其他平台.因此,FireMonkey没有公开Windows消息.
无论你习惯OnMessage
在VCL中做什么,很可能在FireMonkey中具有相同的功能.究竟什么是等价物取决于你的OnMessage
处理程序试图实现的目标.
我不知道在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;
Run Code Online (Sandbox Code Playgroud)
如果需要,可以继续使用MouseMove,MouseUp,MouseWheel,MouseLeave,KeyUp,DragEnter,DragOver,DragDrop和DragLeave.
归档时间: |
|
查看次数: |
3419 次 |
最近记录: |