vb.net鼠标钩子 vb中鼠标移动的代码

VB中接收键盘鼠标的方法添加一文本框;一定时器,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.TextGetKeyName(i)Space(15 - Len(GetKeyName(i)))"键值"iSpace(10 - Len(Str(i)))TimeChr(13)Chr(10)
End If
Next i
End Sub
vb.net中如何禁用键盘和鼠标很简单,你怎么不先问我,还在这提问 。用api函数 , 钩子,设置成全局钩子,然后对钩取来的message消息不做处理,也不返回,这样屏蔽了键盘了 。钩子函数api好像是什么hook的那个 , 还有钩子函数的返回函数,以整个自定义函数的指针作参数
如何在VB.net中用程序控制鼠标移动和点击调用api
在Visual Baisc.net中的声明:
Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = H2 '模拟鼠标左键按下
Public Const MOUSEEVENTF_LEFTUP = H4 ’模拟鼠标左键释放
Public Const MOUSEEVENTF_MIDDLEDOWN = H20 '模拟鼠标中间键按下
Public Const MOUSEEVENTF_MIDDLEUP = H40 '模拟鼠标中间键释放
Public Const MOUSEEVENTF_RIGHTDOWN = H8 '模拟鼠标右键按下
Public Const MOUSEEVENTF_RIGHTUP = H10 '模拟鼠标右键释放
Public Const MOUSEEVENTF_MOVE = H1 '模拟鼠标指针移动
例:
mouse_event MOUSEEVENTF_LEFTDOWN,10,10,0,0
'在(10,10)模拟鼠标左键按下
vb.net键盘钩子的使用哈哈vb.net鼠标钩子,友情提示,vb.net鼠标钩子我只懂VB,不懂VB.net,而且是新手,只会用现在会vb.net鼠标钩子的东西投机取巧 , 思路一说:
首先否定你用HOOK,因为那个太麻烦,只是为了整人不可以这么大动干戈vb.net鼠标钩子的

推荐阅读