vb点虐 监控鼠标键盘 vb监听键盘输入
VB中怎样检测鼠标键盘动作?
鼠标可以触发mousemove 、MouseDown、MouseUp事件。
站在用户的角度思考问题,与客户深入沟通,找到华亭网站设计与华亭网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站建设、成都网站设计、企业官网、英文网站、手机端网站、网站推广、域名申请、虚拟主机、企业邮箱。业务覆盖华亭地区。
键盘可以触发keydown、keypress、keyup事件。
VB点虐 我的程序只有一个窗体,窗体很小,怎么才能检测到鼠标在窗体以外的范围移动,还有键盘输入
用API GetCursorPos
用Timer隔一段时间获取一次鼠标位置。
键盘输入,用 GetKeyboardState
加点分的话就给你完整的代码
Public Class NativeMethods
'获取鼠标位置
Declare Function GetCursorPos Lib "user32.dll" _
(ByRef lpPoint As System.Drawing.Point) as boolean
Private Shared keyState() As Byte
DllImport("user32.dll") _
Private Shared Function GetKeyboardState(ByVal keyState() As Byte) As Boolean
End Function
Private Shared Sub Update()
keyState = New Byte(256) {}
Dim result As Boolean = GetKeyboardState(keyState)
' Check for error:
If result = False Then
Debug.WriteLine("GetKeyBoardState error: " Marshal.GetLastWin32Error)
Throw New Exception("GetKeyBoardState error: " Marshal.GetLastWin32Error)
End If
End Sub
Public Enum LightState
Off
[On]
End Enum
' Example - the keyboard lights...
Public Shared ReadOnly Property CapsLockState() As LightState
Get
Update()
Dim isOn As Boolean = (keyState(Keys.CapsLock) = 1)
Return IIf(isOn, LightState.On, LightState.Off)
End Get
End Property
Public Shared ReadOnly Property NumLockState() As LightState
Get
Update()
Dim isOn As Boolean = (keyState(Keys.NumLock) = 1)
Return IIf(isOn, LightState.On, LightState.Off)
End Get
End Property
Public Shared ReadOnly Property ScrollLockState() As LightState
Get
Update()
Dim isOn As Boolean = (keyState(Keys.Scroll) = 1)
Return IIf(isOn, LightState.On, LightState.Off)
End Get
End Property
End Class
pinvoke点虐 : GetCursorPos (user32)
pinvoke点虐 : GetKeyboardState (user32)
如何在VB点虐 中用程序控制鼠标移动和点击
调用api
在Visual Baisc点虐 中的声明:
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点虐 监控鼠标键盘 vb监听键盘输入
文章位置:http://azwzsj.com/article/ddgpjeh.html