Is there a form KeyPreview event in VB6?

Posted on 2005-04-28
Last Modified: 2008-02-26

I'd like to capture keys being pressed before they go into a controll (ie. text box, grid, etc.)

Example code that doesn't work is as follows:

Create a new project, a new form, and place a text control with default name 'Text1'

place this code in the form:
Private Sub Form_KeyPress(KeyAscii As Integer)
   MsgBox Chr$(KeyAscii)
End Sub

Question by:StevenLogic
    LVL 76

    Expert Comment

    No, The Form _KeyPress event is only possible if the Form itself has the focus. If there any controls on the form that can receive the focus, then the form cannot be in focus.
    LVL 76

    Expert Comment

    LVL 69

    Accepted Solution

    Yes it is working but you have to set the form's KeyPreview property to True

    Author Comment

    Great.  Thanks.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now