I would like to have a KeyPreview functionality within Frames, I mean, that when the input (say, one of the controls of the frame is selected, or the mouse is inside) is in a frame (which would have several panels and other controls) then the keys pressed by the user are first processed by the frame.
Is there a way to do this? I haven't found a property similar to KeyPreview in TFrame.
I'm using version XE5 of RAD Studio, altough I mostly work with C++Builder.
Thanks to my recent "When does a ShortCut fire"-investigation, I have worked out a stand alone solution for your Frame.
In short: all key messages enter in
TWinControl.CNKeyDwon
of the active control. That method callsTWinControl.IsMenuKey
which traverses all parents while determining whether the message is a ShortCut. Is does so by calling itsGetPopupMenu.IsShortCut
method. I have overridden the Frame'sGetPopupMenu
method by creating one if it is not present. Note that at all time you still can add a PopupMenu to the Frame yourself. By subclassingTPopupMenu
and overriding theIsShortCut
method, the Frame'sKeyDown
method is called, which serves as the KeyPreview functionality you require. (I could also have assigned the OnKeyDdown event handler).