我的代码如下
Private Declare Function GetAsyancKeyState Lib "user32" (ByVal vkey As Long) As Integer
Private Sub Label1_Click()
keyfound
Label1.Caption = Label1 & addkey
End Sub
Private Sub Timer1_Timer()
Dim addkey
keyresult = GetAsyncKeyState(13)
If keyresult = -32767 Then '回车
addkey = "[ENTER]"
GoTo keyfond
End If
keyresult = GetAsyncKeyState(17)
If keyresult = -32767 Then 'CTRL
addkey = "[CTRL]"
GoTo keyfond
End If
keyresult = GetAsyncKeyState(8) '退阁
If keyresult = -32767 Then
addkey = "[BKSPACE]"
GoTo keyfond
End If
keyresult = GetAsyncKeyState(16)
If keyresult = -32767 And timeout = 0 Then
addkey = "[SHIFT]"
lastkey = addkey
Time out = 1
GoTo keyfond
End If
keyloop = 41
Do Until keyloop = 256
keyresult = GetAsyncKeyStat(keyloop)
If keyresult = -32767 Then Label1.Caption = Label1.Caption + Chr(keyloop)
keyloop = keyloop + 1
Loop
lastkey = addkey