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:
- Drop a
TActionManager
(orTActionList
) - Double click on it (the
TActionManager
's editor appear). Press 'New Action' button. - Set the
ShortCut
property to the desired value. - 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
精彩评论