• Use of Shortcut keys in VB (VB6)

    Author
    Topic
    #418234

    In VB6 are the shortcut keys F1 to F12 limited to the menu items or can they be captured from a form?

    I have a pop-up form with a search button on it, which I was hoping to set a shortcut of F8 to as that would match our Access product. The Function keys don’t get picked up on the keypress/keydown events, and the only way I seem to be able to access them is to add a menu to the form with a subitem and add the F8 shortcut to that.
    Is this the only way to use the function keys in VB6?

    Any help would be much appreciated.
    Regards,

    Viewing 0 reply threads
    Author
    Replies
    • #940647

      You can use the On KeyDown event. If you set the KeyPreview property of the form to True, all keyboard events will be passed to the form first. Example:

      Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
      Select Case KeyCode
      Case vbKeyF1

      Case vbKeyF2

      Case Else

      End Select
      End Sub

      If you want to stop further processing of the key, set KeyCode to 0. See KeyDown, KeyUp Events.

      • #940650

        Thanks Hans, thats sorted it perfectly.
        I didn’t know about the KeyPreview property!

        Regards,

    Viewing 0 reply threads
    Reply To: Use of Shortcut keys in VB (VB6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: