如何在按键后出现消息框

How to make a message box appear after pressing a key

我目前正在使用 Visual Basic 6.0,想知道当用户按下键盘上的特定键(例如 时,您如何使消息框或其他代码 appear/activate F1F2.

在表单中使用 Form_KeyDown(Keycode, Shift) 方法:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

    If KeyCode = vbKeyF1 Then
        //do something here if F1 key is pressed
        //or call a method


    End If
End Sub

此外,您可能还想将表单的 KeyPreview 属性 设置为 true。