开发者

How to fire KeyPreview Event when form has a TActionMainMenuBar

When I开发者_Go百科 set the property KeyPreview = TRUE on my main form (MDI Parent) the OnKeyDown, OnKeyUp or OnKeyPress events don't get fired. When pressing keys, I can navigate the main menu (TActionMenuBar). It seems the menu bar has the control over the key events.

How can I fire an event, when the user is pressing a key (e.g. the VK_RETURN key)?

I am using Delphi 2009


From the comments I see that you want to do a certain action (eg. open a form) when a certain key is pressed.

For this, you can assign your shortcut key to an TAction and write the appropriate code in the TAction.OnExecute

Steps:

  1. Drop a TActionManager (or TActionList)
  2. Double click on it (the TActionManager's editor appear). Press 'New Action' button.
  3. Set the ShortCut property to the desired value.
  4. Write the appropriate code in OnExecute event.

Note that on step 3. (perhaps) you (and most probably your users) will have trouble assigning the Enter key to something so uncommon like opening a form. 'Enter' has a very defined meaning in Windows.

I'd suggest to assign a functional key (F2-F9 usually) and/or Ctrl+[the first letter of your form's name]

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜