PRB: Arrow Keys Do Not Always Produce a KeyDown Event

Last reviewed: September 17, 1996
Article ID: Q138530
The information in this article applies to:
  • Microsoft Visual Basic for Windows, version 3.0
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

SYMPTOMS

The KeyDown event for a form is not invoked when using the arrow (navigational) keys, even though the Keypreview property is set to True for the form. Instead the arrow keys cause other controls to gain the focus, even if the TabStop property is set to False for those controls.

NOTE: The DEL key may not trigger the KeyDown event either. For instance, in Visual Basic 4.0 the DEL key in a masked edit box does not trigger the KeyDown event.

STATUS

Microsoft is researching this behavior and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Whether or not the form receives a KeyDown event depends on the type of control that has the focus when the arrow key is pressed. The KeyDown event of the form will be correctly activated if the arrow keys are used when a control such as a text box, a list box, or a picture box has the focus. The KeyDown event for the form is not activated when Command buttons, check boxes, and option buttons have the focus when an arrow key is pressed. In all cases, this behavior does not depend on whether Tabstop is set to True or False for the control.

Steps to Reproduce Behavior

  1. Create a new project in Visual Basic. Form1 is created by default.

  2. Set the KeyPreview property to True for Form1.

  3. Add two Command buttons to Form1.

  4. Set the Tabstop property of both Command buttons to False.

  5. Add a DoEvents statement to the Form_KeyDown procedure. Set a breakpoint on the line by highlighting DoEvents and pressing the F9 key.

  6. Run the program by pressing the F5 key. Pressing an arrow key does not activate the KeyDown event of the form.


Additional reference words: 4.00 3.00 vb4win vb4all
KBCategory: kbui kbprg kbprb
KBSubcategory: PrgOther


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 17, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.