Delphi 如何获得;输入“;使用Tapplicationevent组件的键

Delphi 如何获得;输入“;使用Tapplicationevent组件的键,delphi,Delphi,我想在按下“enter”键时获得“enter”键消息。我尝试使用Tapplicationevent组件。代码为 procedure TForm6.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); begin if Msg.message=WM_KeyDown then if msg.wParam=Windows.VK_RETURN then begin

我想在按下“enter”键时获得“enter”键消息。我尝试使用Tapplicationevent组件。代码为

procedure TForm6.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
begin
    if   Msg.message=WM_KeyDown   then
      if   msg.wParam=Windows.VK_RETURN   then
      begin
          Button1.Click();
          handled:=True;
      end;
end;

但它不起作用。如何改进?谢谢

您只想在特定窗体上或在整个应用程序中按此键时查看它吗?表单上的OnKeyDown、OnKeyUp或OnKeyPress事件可能更适合(请确保正确设置KeyPreview属性),具体取决于您的使用情况。我还在阅读上面的代码,您希望在TForm6上按Enter键时单击特定的按钮。您是否查看了TButton.Default属性的功能?屏幕上看不到
TapplAction
的顶级窗口,因此不太可能接收键盘输入。您的代码是正确的,但您解决问题的方法可能不正确。您试图解决的是什么?@Free-OnMessage事件将为线程接收到的每个排队消息触发。@Free咨询
TApplication.OnMessage
事件(扩展为
TApplicationEvents.OnMessage
事件)对于从主消息队列中检索到的每条消息,在对其进行处理并发送到应用程序的其余部分之前,都会触发。这包括键盘和鼠标信息。