我做了一个键盘测试程序,可以把各按键的键值显示出来,但是按下F10后再按其他功能键就不灵了,除非再次按下F10键,程序如下,请各位朋友指正:
Private Sub Form_KeyPress(KeyAscii As Integer)
    Label1.Caption = keyAscii
End Sub
上面这一段可以显示数字键及符号键的键值,但对功能键无效
Private Sub Form_Keydown(KeyCode As Integer, Shift As Integer)
    Label1.Caption = KeyCode
End Sub
这一段可以显示功能键(F1-F12)的键值,也可以显示数字键的键值,但与上面程序显示的值不一样重点要解决按下F10再按其他键没反应的问题!!!

解决方案 »

  1.   

    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
     
     
    Private Sub Form_Keydown(KeyCode As Integer, Shift As Integer)
     If GetAsyncKeyState(vbKeyF10) <> 0 Then
    MsgBox "你按了F10!"
    End If
     
    If GetAsyncKeyState(vbKeyF12) <> 0 Then
    MsgBox "你按了F12!"
    End IfIf GetAsyncKeyState(vbKeyF11) <> 0 Then
    MsgBox "你按了F11!"
    End If If GetAsyncKeyState(vbKeyA) <> 0 Then
    MsgBox "你按了a!"
    End IfIf GetAsyncKeyState(vbKeyB) <> 0 Then
    MsgBox "你按了b!"
    End If'……
    End Sub
      

  2.   

    如果不用MSGBOX,直接在LABEL中显示,还是有那样的问题啊!!!按一次F10,按其他键就没反应了。只能再按一次F10,好像F10是锁定键,按一次锁住,再按一次解锁。