markus_ja
markus_ja

Reputation: 2951

How to fire KeyPreview Event when form has a TActionMainMenuBar

When I 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

Upvotes: 1

Views: 2499

Answers (1)

John Thomas
John Thomas

Reputation: 4135

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

Upvotes: 0

Related Questions