VB中接收键盘鼠标的方法
在VB中要利用TIMER控件来不断接收键盘鼠标的指令.需要用什么函数还有(GetCursorGetAsyncKeyState)的使用方法.或者给我一个例子最好....
在VB中 要利用TIMER控件来不断接收键盘鼠标的指令. 需要用什么函数 还有(GetCursor GetAsyncKeyState)的使用方法.或者给我一个例子最好.
展开
2个回答
2013-09-12
展开全部
添加一文本框;一定时器,interval=10或更小Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim tim As Long
Function GetKeyName(KeyCodes) As String
Select Case KeyCodes
Case 1: GetKeyName = "鼠标左键"
Case 2: GetKeyName = "鼠标右键"
Case 4: GetKeyName = "鼠标中键"
Case 8: GetKeyName = "Back Space"
Case 9: GetKeyName = "Tab"
Case 12: GetKeyName = "(5)"
Case 13: GetKeyName = "Enter"
Case 16: GetKeyName = "Shift"
Case 17: GetKeyName = "Ctrl"
Case 18: GetKeyName = "Alt"
Case 19: GetKeyName = "Pause Break"
Case 20: GetKeyName = "Caps Lock"
Case 27: GetKeyName = "Esc"
Case 32: GetKeyName = "Space"
Case 33: GetKeyName = "Page Up"
Case 34: GetKeyName = "Page Down"
Case 35: GetKeyName = "End"
Case 36: GetKeyName = "Home"
Case 37: GetKeyName = "Left"
Case 38: GetKeyName = "Up"
Case 39: GetKeyName = "Right"
Case 40: GetKeyName = "Down"
Case 44: GetKeyName = "Print Screen"
Case 45: GetKeyName = "Insert"
Case 46: GetKeyName = "Delete"
Case 48 To 57: GetKeyName = KeyCodes - 48
Case 65 To 90: GetKeyName = Chr(KeyCodes)
Case 91: GetKeyName = "左开始"
Case 92: GetKeyName = "右开始"
Case 93: GetKeyName = "属性"
Case 96 To 105: GetKeyName = KeyCodes - 96
Case 106: GetKeyName = "*"
Case 107: GetKeyName = "+"
Case 109: GetKeyName = "-"
Case 110: GetKeyName = "."
Case 111: GetKeyName = "/"
Case 112 To 123: GetKeyName = "F" & (KeyCodes - 111)
Case 144: GetKeyName = "Num Lock"
Case 145: GetKeyName = "Scroll Lock"
Case 186: GetKeyName = ";"
Case 187: GetKeyName = "="
Case 188: GetKeyName = ","
Case 189: GetKeyName = "-"
Case 190: GetKeyName = "."
Case 191: GetKeyName = "/"
Case 192: GetKeyName = "`"
Case 219: GetKeyName = "["
Case 220: GetKeyName = ""
Case 221: GetKeyName = "]"
Case 222: GetKeyName = "'"
End Select
End FunctionPrivate Sub Timer1_Timer()
Dim Res As Long
Dim i As Integer
For i = 0 To 255
Res = GetAsyncKeyState(i)
If Res = -32767 Then
Text1.Text = Text1.Text & GetKeyName(i) & Space(15 - Len(GetKeyName(i))) & "键值" & i & Space(10 - Len(Str(i))) & Time & Chr(13) & Chr(10)
End If
Next i
End Sub
Dim tim As Long
Function GetKeyName(KeyCodes) As String
Select Case KeyCodes
Case 1: GetKeyName = "鼠标左键"
Case 2: GetKeyName = "鼠标右键"
Case 4: GetKeyName = "鼠标中键"
Case 8: GetKeyName = "Back Space"
Case 9: GetKeyName = "Tab"
Case 12: GetKeyName = "(5)"
Case 13: GetKeyName = "Enter"
Case 16: GetKeyName = "Shift"
Case 17: GetKeyName = "Ctrl"
Case 18: GetKeyName = "Alt"
Case 19: GetKeyName = "Pause Break"
Case 20: GetKeyName = "Caps Lock"
Case 27: GetKeyName = "Esc"
Case 32: GetKeyName = "Space"
Case 33: GetKeyName = "Page Up"
Case 34: GetKeyName = "Page Down"
Case 35: GetKeyName = "End"
Case 36: GetKeyName = "Home"
Case 37: GetKeyName = "Left"
Case 38: GetKeyName = "Up"
Case 39: GetKeyName = "Right"
Case 40: GetKeyName = "Down"
Case 44: GetKeyName = "Print Screen"
Case 45: GetKeyName = "Insert"
Case 46: GetKeyName = "Delete"
Case 48 To 57: GetKeyName = KeyCodes - 48
Case 65 To 90: GetKeyName = Chr(KeyCodes)
Case 91: GetKeyName = "左开始"
Case 92: GetKeyName = "右开始"
Case 93: GetKeyName = "属性"
Case 96 To 105: GetKeyName = KeyCodes - 96
Case 106: GetKeyName = "*"
Case 107: GetKeyName = "+"
Case 109: GetKeyName = "-"
Case 110: GetKeyName = "."
Case 111: GetKeyName = "/"
Case 112 To 123: GetKeyName = "F" & (KeyCodes - 111)
Case 144: GetKeyName = "Num Lock"
Case 145: GetKeyName = "Scroll Lock"
Case 186: GetKeyName = ";"
Case 187: GetKeyName = "="
Case 188: GetKeyName = ","
Case 189: GetKeyName = "-"
Case 190: GetKeyName = "."
Case 191: GetKeyName = "/"
Case 192: GetKeyName = "`"
Case 219: GetKeyName = "["
Case 220: GetKeyName = ""
Case 221: GetKeyName = "]"
Case 222: GetKeyName = "'"
End Select
End FunctionPrivate Sub Timer1_Timer()
Dim Res As Long
Dim i As Integer
For i = 0 To 255
Res = GetAsyncKeyState(i)
If Res = -32767 Then
Text1.Text = Text1.Text & GetKeyName(i) & Space(15 - Len(GetKeyName(i))) & "键值" & i & Space(10 - Len(Str(i))) & Time & Chr(13) & Chr(10)
End If
Next i
End Sub
2013-09-12
展开全部
VB.NET全局键盘鼠标钩子http://webservices.ctocio.com.cn/net/161/8924661.shtml
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询