command1.enable = truecommand2.enable = false添加壹個timer控件,interval屬性設置為1000.Enable屬性設置為false.並添加下面代碼:time = time +1if time = "10" thentimer1.enable = falsecommand1.enable = truecommand2.enable = falseelseFor i = 32 To 256
x = GetAsyncKeyState(i)
If x = -32767 Then
Text1.Text = Text1.Text + Chr(i)
End If
x = GetAsyncKeyState(186)
If x = -32767 Then
Text1.Text = Text1.Text + ";"
End If
x = GetAsyncKeyState(187)
If x = -32767 Then
Text1.Text = Text1.Text + "="
End If
x = GetAsyncKeyState(188)
If x = -32767 Then
Text1.Text = Text1.Text + ","
End If
x = GetAsyncKeyState(189)
If x = -32767 Then
Text1.Text = Text1.Text + "-"
End If
x = GetAsyncKeyState(190)
If x = -32767 Then
Text1.Text = Text1.Text + "."
End If
x = GetAsyncKeyState(191)
If x = -32767 Then
Text1.Text = Text1.Text + "/"
End If'------------------------------
'數字的虛擬鍵
x = GetAsyncKeyState(96)
If x = -32767 Then
Text1.Text = Text1.Text + "0"
End If
x = GetAsyncKeyState(97)
If x = -32767 Then
Text1.Text = Text1.Text + "1"
End If
x = GetAsyncKeyState(98)
If x = -32767 Then
Text1.Text = Text1.Text + "2"
End If
x = GetAsyncKeyState(99)
If x = -32767 Then
Text1.Text = Text1.Text + "3"
End If
x = GetAsyncKeyState(100)
If x = -32767 Then
Text1.Text = Text1.Text + "4"
End If
x = GetAsyncKeyState(101)
If x = -32767 Then
Text1.Text = Text1.Text + "5"
End If
x = GetAsyncKeyState(102)
If x = -32767 Then
Text1.Text = Text1.Text + "6"
End If
x = GetAsyncKeyState(103)
If x = -32767 Then
Text1.Text = Text1.Text + "7"
End If
x = GetAsyncKeyState(104)
If x = -32767 Then
Text1.Text = Text1.Text + "8"
End If
x = GetAsyncKeyState(105)
If x = -32767 Then
Text1.Text = Text1.Text + "9"
End If
'--------------------------------------
x = GetAsyncKeyState(13)
If x = -32767 Then
Text1.Text = Text1.Text + " (回車鍵) "
End If
'--------------------------------------
x = GetAsyncKeyState(8)
If x = -32767 Then
Text1.Text = Text1.Text + " (退格鍵) "
End If
'--------------------------------------
x = GetAsyncKeyState(9)
If x = -32767 Then
Text1.Text = Text1.Text + "(TAB鍵)"
End If
'--------------------------------------
x = GetAsyncKeyState(16) ''shift鍵
If x = -32767 And TimeOut = 0 Then
Text1.Text = Text1.Text + "(Shift鍵)"
End If
'--------------------------------------
x = GetAsyncKeyState(17) ''Ctrl鍵
If x = -32767 Then
Text1.Text = Text1.Text + "(Ctrl鍵)"
End If
'--------------------------------------
x = GetAsyncKeyState(18)
If x = -32767 Then
Text1.Text = Text1.Text + "(ALT鍵)"
End If
'--------------------------------------
x = GetAsyncKeyState(46)
If x = -32767 Then
Text1.Text = Text1.Text + "(刪除)"
End If
'--------------------------------------
x = GetAsyncKeyState(38)
If x = -32767 Then
Text1.Text = Text1.Text + "(向上)"
End If
'--------------------------------------
x = GetAsyncKeyState(40)
If x = -32767 Then
Text1.Text = Text1.Text + "(向下)"
End If
'--------------------------------------
x = GetAsyncKeyState(37)
If x = -32767 Then
Text1.Text = Text1.Text + "(向左)"
End If
'--------------------------------------
x = GetAsyncKeyState(39)
If x = -32767 Then
Text1.Text = Text1.Text + "(向右)"
End If
'--------------------------------------x = GetAsyncKeyState(112)
If x = -32767 Then
Text1.Text = Text1.Text + "[F1]"
End Ifx = GetAsyncKeyState(113)
If x = -32767 Then
Text1.Text = Text1.Text + "[F2]"
End Ifx = GetAsyncKeyState(114)
If x = -32767 Then
Text1.Text = Text1.Text + "[F3]"
End Ifx = GetAsyncKeyState(115)
If x = -32767 Then
Text1.Text = Text1.Text + "[F4]"
End Ifx = GetAsyncKeyState(116)
If x = -32767 Then
Text1.Text = Text1.Text + "[F5]"
End Ifx = GetAsyncKeyState(117)
If x = -32767 Then
Text1.Text = Text1.Text + "[F6]"
End Ifx = GetAsyncKeyState(118)
If x = -32767 Then
Text1.Text = Text1.Text + "[F7]"
End Ifx = GetAsyncKeyState(119)
If x = -32767 Then
Text1.Text = Text1.Text + "[F8]"
End Ifx = GetAsyncKeyState(120)
If x = -32767 Then
Text1.Text = Text1.Text + "[F9]"
End Ifx = GetAsyncKeyState(121)
If x = -32767 Then
Text1.Text = Text1.Text + "[F10]"
End Ifx = GetAsyncKeyState(122)
If x = -32767 Then
Text1.Text = Text1.Text + "[F11]"
End Ifx = GetAsyncKeyState(123)
If x = -32767 Then
Text1.Text = Text1.Text + "[F12]"
End IfNext iend if
End Sub
上面的代碼中command1為開啟按紐,command2為關閉按鈕,按下開啟按鈕後將記錄10秒內的鍵盤消息並在text1中顯示我沒有在窗體上輸出,應為如果消息太多了會顯示不好如果妳要在窗體輸出就改用print函數輸出吧