用API函数控制鼠标
#1 一、锁定鼠标
所谓锁定鼠标,就是将鼠标指针固定到当前位置,既不能单击,也不能双击,就跟死机一般。方法如下:
声明API函数及类型:
Private Declare Function ClipCursorBynum& Lib“user32” Alias“ClipCursor” (ByVal lpRect As Long)
Private Declare Function ClipCursor Lib“user32” (lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
锁定鼠标:
Dim cc As RECT
With cc
.Top = 0
.Left = 0
.Right = 0
.Bottom = 0
End With
ClipCursor cc
释放鼠标:
ClipCursorBynum 0
#1 二、剪切鼠标
所谓剪切鼠标就是将鼠标指针限定到指定区域,在该区域内,鼠标能进行如单击、双击的动作。方法如下:
声明API函数及类型:
Private Declare Function ClipCursorBynum& Lib“user32” Alias “ClipCursor” (ByVal lpRect As Long)
Private Declare Function GetWindowRect Lib“user32”(ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function ClipCursor Lib“user32” (lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
剪切鼠标(假设将鼠标指针限定到一窗体Form1内):
Dim cc As RECT
GetWindowRect Form1.hwnd, cc
ClipCursor cc
释放鼠标:
ClipCursorBynum 0
#1 三、隐藏鼠标指针
声明API函数:
Private Declare Function ShowCursor Lib “user32” (ByVal bShow As Long) As Long
隐藏鼠标指针:
ShowCursor 0
显示鼠标指针:
ShowCursor 1
#1 四、按钮配置与双击速度
单击菜单“开始→设置→控制面板”,打开“控制面板”窗口,双击“鼠标”,打开“鼠标属性”的对话框,选择“按钮”选项卡。看见了吗?一切尽在不言中。
㈠ 按钮配置:
声明API函数:
Private Declare Function SwapMouseButton Lib “user32” (ByVal bSwap As Long) As Long
左手习惯:
SwapMouseButton 1
右手习惯:
SwapMouseButton 0
㈡ 双击速度:
声明API函数:
Private Declare Function SetDoubleClickTime Lib “user32” (ByVal wCount As Long) As Long
设置鼠标的双击速度:(正常的双击速度约为300毫秒)
SetDoubleClickTime 300