如何用VB6统计键盘上各键敲击的次数?????
我想用VB6统计一下某段时间内键盘上各键(只包括主键盘区内除ESC和F1~12的键)的敲击次数,就是说当时间结束时能统计出每个键被敲击了多少次.注意我是在中文输入法的状态...
我想用VB6统计一下某段时间内键盘上各键(只包括主键盘区内除ESC和F1~12的键)的敲击次数,就是说当时间结束时能统计出每个键被敲击了多少次.注意我是在中文输入法的状态下敲击的,有的程序只能在英文输入法下计算,这不合要求.请各位大虾给出全部代码...答案经采纳还有加分!谢谢!
展开
2个回答
展开全部
用记事本保存下面的代码为“frmTest.frm”
新建工程,把窗体添加进工程,记得,只能添加,不要直接打开窗体
================frmTest.frm====================
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin MSComctlLib.ListView ListView1
Height = 1335
Left = 720
TabIndex = 0
Top = 600
Width = 1935
_ExtentX = 3413
_ExtentY = 2355
View = 3
LabelEdit = 1
LabelWrap = -1 'True
HideSelection = -1 'True
FullRowSelect = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
Appearance = 1
NumItems = 2
BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628}
Text = "按键"
Object.Width = 2540
EndProperty
BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 1
Text = "次数"
Object.Width = 2540
EndProperty
End
Begin VB.Timer Timer1
Interval = 10
Left = 1800
Top = 1320
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim Sums(32 To 127) As Long
Private Sub Form_Load()
For i = LBound(Sums) To UBound(Sums)
ListView1.ListItems.Add , , KeyCodeToStr2(i)
Next
End Sub
Private Sub Form_Resize()
ListView1.Move 0, 0, ScaleWidth, ScaleHeight
End Sub
Private Sub Timer1_Timer()
Static a As Long
Dim b As Long
For i = LBound(Sums) To UBound(Sums)
If GetAsyncKeyState(i) And 1 Then Sums(i) = Sums(i) + 1
Next
If a > 100 Then
a = 0
For i = LBound(Sums) To UBound(Sums)
b = b + 1
ListView1.ListItems(b).SubItems(1) = Sums(i)
Next
Else
a = a + 1
End If
End Sub
Public Function KeyCodeToStr2(KeyCode) As String
Select Case KeyCode
Case vbKeyShift
KeyCodeToStr2 = "Shift"
Case vbKeyMenu
KeyCodeToStr2 = "Alt"
Case vbKeyControl
KeyCodeToStr2 = "Ctrl"
Case vbKeyNumpad0
KeyCodeToStr2 = "Num 0"
Case vbKeyNumpad1
KeyCodeToStr2 = "Num 1"
Case vbKeyNumpad2
KeyCodeToStr2 = "Num 2"
Case vbKeyNumpad3
KeyCodeToStr2 = "Num 3"
Case vbKeyNumpad4
KeyCodeToStr2 = "Num 4"
Case vbKeyNumpad5
KeyCodeToStr2 = "Num 5"
Case vbKeyNumpad6
KeyCodeToStr2 = "Num 6"
Case vbKeyNumpad7
KeyCodeToStr2 = "Num 7"
Case vbKeyNumpad8
KeyCodeToStr2 = "Num 8"
Case vbKeyNumpad9
KeyCodeToStr2 = "Num 9"
Case vbKeyAdd
KeyCodeToStr2 = "Num +"
Case vbKeySubtract
KeyCodeToStr2 = "Num -"
Case vbKeyMultiply
KeyCodeToStr2 = "Num *"
Case vbKeyDivide
KeyCodeToStr2 = "Num /"
Case vbKeyDecimal
KeyCodeToStr2 = "Num ."
Case vbKeySeparator
KeyCodeToStr2 = "Num Enter"
Case vbKeyEscape
KeyCodeToStr2 = "Escape"
Case vbKeyF1
KeyCodeToStr2 = "F1"
Case vbKeyF2
KeyCodeToStr2 = "F2"
Case vbKeyF3
KeyCodeToStr2 = "F3"
Case vbKeyF4
KeyCodeToStr2 = "F4"
Case vbKeyF5
KeyCodeToStr2 = "F5"
Case vbKeyF6
KeyCodeToStr2 = "F6"
Case vbKeyF7
KeyCodeToStr2 = "F7"
Case vbKeyF8
KeyCodeToStr2 = "F8"
Case vbKeyF9
KeyCodeToStr2 = "F9"
Case vbKeyF10
KeyCodeToStr2 = "F10"
Case vbKeyF11
KeyCodeToStr2 = "F11"
Case vbKeyF12
KeyCodeToStr2 = "F12"
Case vbKeySpace
KeyCodeToStr2 = "Space"
Case vbKeyBack
KeyCodeToStr2 = "BackSpace"
Case vbKeyInsert
KeyCodeToStr2 = "Insert"
Case vbKeyDelete
KeyCodeToStr2 = "Delete"
Case vbKeyHome
KeyCodeToStr2 = "Home"
Case vbKeyEnd
KeyCodeToStr2 = "End"
Case vbKeyPageUp
KeyCodeToStr2 = "PageUp"
Case vbKeyPageDown
KeyCodeToStr2 = "PageDown"
Case vbKeyPause
KeyCodeToStr2 = "Pause"
Case vbKeyPrint
KeyCodeToStr2 = "Print Screen"
Case vbKeyCapital
KeyCodeToStr2 = "Caps Lock"
Case vbKeyNumlock
KeyCodeToStr2 = "Num Lock"
Case vbKeyScrollLock
KeyCodeToStr2 = "Scroll Lock"
Case vbKeyLeft
KeyCodeToStr2 = "Left"
Case vbKeyRight
KeyCodeToStr2 = "Right"
Case vbKeyUp
KeyCodeToStr2 = "Up"
Case vbKeyDown
KeyCodeToStr2 = "Down"
Case vbKeyReturn
KeyCodeToStr2 = "Enter"
Case 189
KeyCodeToStr2 = "-"
Case 187
KeyCodeToStr2 = "="
Case 219
KeyCodeToStr2 = "[ ({)"
Case 221
KeyCodeToStr2 = "] (})"
Case 220
KeyCodeToStr2 = "\ (|)"
Case 186
KeyCodeToStr2 = "; (:)"
Case 222
KeyCodeToStr2 = "' (" & """" & ")"
Case 188
KeyCodeToStr2 = ", (<)"
Case 190
KeyCodeToStr2 = ". (>)"
Case 191
KeyCodeToStr2 = "/ (?)"
Case 192
KeyCodeToStr2 = "` (~)"
Case Else
KeyCodeToStr2 = UCase(Chr(KeyCode))
End Select
End Function
新建工程,把窗体添加进工程,记得,只能添加,不要直接打开窗体
================frmTest.frm====================
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin MSComctlLib.ListView ListView1
Height = 1335
Left = 720
TabIndex = 0
Top = 600
Width = 1935
_ExtentX = 3413
_ExtentY = 2355
View = 3
LabelEdit = 1
LabelWrap = -1 'True
HideSelection = -1 'True
FullRowSelect = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
Appearance = 1
NumItems = 2
BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628}
Text = "按键"
Object.Width = 2540
EndProperty
BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 1
Text = "次数"
Object.Width = 2540
EndProperty
End
Begin VB.Timer Timer1
Interval = 10
Left = 1800
Top = 1320
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim Sums(32 To 127) As Long
Private Sub Form_Load()
For i = LBound(Sums) To UBound(Sums)
ListView1.ListItems.Add , , KeyCodeToStr2(i)
Next
End Sub
Private Sub Form_Resize()
ListView1.Move 0, 0, ScaleWidth, ScaleHeight
End Sub
Private Sub Timer1_Timer()
Static a As Long
Dim b As Long
For i = LBound(Sums) To UBound(Sums)
If GetAsyncKeyState(i) And 1 Then Sums(i) = Sums(i) + 1
Next
If a > 100 Then
a = 0
For i = LBound(Sums) To UBound(Sums)
b = b + 1
ListView1.ListItems(b).SubItems(1) = Sums(i)
Next
Else
a = a + 1
End If
End Sub
Public Function KeyCodeToStr2(KeyCode) As String
Select Case KeyCode
Case vbKeyShift
KeyCodeToStr2 = "Shift"
Case vbKeyMenu
KeyCodeToStr2 = "Alt"
Case vbKeyControl
KeyCodeToStr2 = "Ctrl"
Case vbKeyNumpad0
KeyCodeToStr2 = "Num 0"
Case vbKeyNumpad1
KeyCodeToStr2 = "Num 1"
Case vbKeyNumpad2
KeyCodeToStr2 = "Num 2"
Case vbKeyNumpad3
KeyCodeToStr2 = "Num 3"
Case vbKeyNumpad4
KeyCodeToStr2 = "Num 4"
Case vbKeyNumpad5
KeyCodeToStr2 = "Num 5"
Case vbKeyNumpad6
KeyCodeToStr2 = "Num 6"
Case vbKeyNumpad7
KeyCodeToStr2 = "Num 7"
Case vbKeyNumpad8
KeyCodeToStr2 = "Num 8"
Case vbKeyNumpad9
KeyCodeToStr2 = "Num 9"
Case vbKeyAdd
KeyCodeToStr2 = "Num +"
Case vbKeySubtract
KeyCodeToStr2 = "Num -"
Case vbKeyMultiply
KeyCodeToStr2 = "Num *"
Case vbKeyDivide
KeyCodeToStr2 = "Num /"
Case vbKeyDecimal
KeyCodeToStr2 = "Num ."
Case vbKeySeparator
KeyCodeToStr2 = "Num Enter"
Case vbKeyEscape
KeyCodeToStr2 = "Escape"
Case vbKeyF1
KeyCodeToStr2 = "F1"
Case vbKeyF2
KeyCodeToStr2 = "F2"
Case vbKeyF3
KeyCodeToStr2 = "F3"
Case vbKeyF4
KeyCodeToStr2 = "F4"
Case vbKeyF5
KeyCodeToStr2 = "F5"
Case vbKeyF6
KeyCodeToStr2 = "F6"
Case vbKeyF7
KeyCodeToStr2 = "F7"
Case vbKeyF8
KeyCodeToStr2 = "F8"
Case vbKeyF9
KeyCodeToStr2 = "F9"
Case vbKeyF10
KeyCodeToStr2 = "F10"
Case vbKeyF11
KeyCodeToStr2 = "F11"
Case vbKeyF12
KeyCodeToStr2 = "F12"
Case vbKeySpace
KeyCodeToStr2 = "Space"
Case vbKeyBack
KeyCodeToStr2 = "BackSpace"
Case vbKeyInsert
KeyCodeToStr2 = "Insert"
Case vbKeyDelete
KeyCodeToStr2 = "Delete"
Case vbKeyHome
KeyCodeToStr2 = "Home"
Case vbKeyEnd
KeyCodeToStr2 = "End"
Case vbKeyPageUp
KeyCodeToStr2 = "PageUp"
Case vbKeyPageDown
KeyCodeToStr2 = "PageDown"
Case vbKeyPause
KeyCodeToStr2 = "Pause"
Case vbKeyPrint
KeyCodeToStr2 = "Print Screen"
Case vbKeyCapital
KeyCodeToStr2 = "Caps Lock"
Case vbKeyNumlock
KeyCodeToStr2 = "Num Lock"
Case vbKeyScrollLock
KeyCodeToStr2 = "Scroll Lock"
Case vbKeyLeft
KeyCodeToStr2 = "Left"
Case vbKeyRight
KeyCodeToStr2 = "Right"
Case vbKeyUp
KeyCodeToStr2 = "Up"
Case vbKeyDown
KeyCodeToStr2 = "Down"
Case vbKeyReturn
KeyCodeToStr2 = "Enter"
Case 189
KeyCodeToStr2 = "-"
Case 187
KeyCodeToStr2 = "="
Case 219
KeyCodeToStr2 = "[ ({)"
Case 221
KeyCodeToStr2 = "] (})"
Case 220
KeyCodeToStr2 = "\ (|)"
Case 186
KeyCodeToStr2 = "; (:)"
Case 222
KeyCodeToStr2 = "' (" & """" & ")"
Case 188
KeyCodeToStr2 = ", (<)"
Case 190
KeyCodeToStr2 = ". (>)"
Case 191
KeyCodeToStr2 = "/ (?)"
Case 192
KeyCodeToStr2 = "` (~)"
Case Else
KeyCodeToStr2 = UCase(Chr(KeyCode))
End Select
End Function
程经理
2025-01-01 广告
2025-01-01 广告
硕方线号机键盘无反应可能由多种原因引起。首先,检查键盘连线是否插好,若未插好则重新插好。其次,若键盘连线正常,可能是键盘PCB组件损坏,需要更换。此外,也有可能是主板或其他硬件故障导致,需进一步检查或维修。请注意,以上信息仅供参考,若问题仍...
点击进入详情页
本回答由程经理提供
展开全部
用这个就可以了
剑响键盘记录 V2.2
追求简单好用的中文键盘记录软件。支持祡光拼音等绝大多数输入法。后台程序隐密性好,没有任何进程。采用了智能方法过滤无意义信息。未注册版本对单机使用没有任何限制,注册用户可以同时记录多台电脑,像本地一样简单查看,内有详细易懂使用实例,点[新手上路]学习。
×尊重他人隐私请在法律许可范围内使用×
下载地址:http://www.xdowns.com/soft/4/96/2006/Soft_23970.html
剑响键盘记录 V2.2
追求简单好用的中文键盘记录软件。支持祡光拼音等绝大多数输入法。后台程序隐密性好,没有任何进程。采用了智能方法过滤无意义信息。未注册版本对单机使用没有任何限制,注册用户可以同时记录多台电脑,像本地一样简单查看,内有详细易懂使用实例,点[新手上路]学习。
×尊重他人隐私请在法律许可范围内使用×
下载地址:http://www.xdowns.com/soft/4/96/2006/Soft_23970.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询