RE: KeyPreview doesn't trap Enter key

From: Norman Diamond (ndiamond_at_nospam.nospam)
Date: 10/12/04


Date: Mon, 11 Oct 2004 18:17:03 -0700


""Peter Huang"" wrote:

> This behavior is by design. The problem is that these controls are
> subclassed off a default control type provided by Windows. For more
> information, please see the Visual Basic version 3.0 "Professional Features
> Book 1" manual, "Control Development Guide," page 87, the paragraph that
> begins, "If Click were implemented ..."
> The superclass in Windows treats these keys in a special way, so that the
> control always gets the keystroke before the form does.

I apologize for this late reply, after travelling for two weeks. Mr. Huang
sent e-mail
asking if his posted answer met my needs. I don't have VB3 (only VB6 and
later)
but think I understand Mr. Huang's posted reply. I must followup with two
points.

One problem is, as stated in the base note, I still don't know a proper
workaround:
>> I tried an absurd workaround. I deleted some command buttons and created
>> option buttons instead, and set their style to graphical. Now Form_KeyDown()
>> gets called when the Enter key is pressed. But now, tabbing from another
>> control to an option button causes btn1_Click() to get called.
>> I only want btn1_Click() to get called when the user really clicks (using
>> the mouse) or presses the space bar when the button has focus. These two
>> methods are acceptable. Doing a click when simply tabbing to the control is
>> not acceptable. Doing a click when the user presses the Enter key is not
>> acceptable.

The other issue is that, although the superclass works as designed and the
buttons
operate as designed, this doesn't mean that the design is good. KeyPreview is
supposed to have a certain meaning, the main documentation of that meaning is
pretty clear and it is not easy to find the two KB articles that Mr. Huang
pointed me
to. In order to implement KeyPreview properly, it seems that a different
superclass
(or perhaps omitting all use of superclasses) would be necessary for option
buttons,
and that is what should have been done.

(Of course I think that it "should" not matter too much, because the Enter key
"should" not be used the way our customer said to use it. But that is my
opinion.
My job does not depend on my opinion, it depends on obeying customers.)