1.变换鼠标左右键
添加 Command1
Private Declare Function SwapMouButton Lib "ur32" (ByVal bSwap As Long) As Long
Private Sub Command1_Click()疏通下水道
SwapMouButton True
MsgBox "退出前你现在是左撇子"
End Sub
Private Sub Form_Unload(Cancel As Integer)
SwapMouButton Fal
MsgBox "鼠标左右键已灰复"
End Sub
2.得知鼠标位置
'添加 Timer1
Option Explicit
'*********************** 得知鼠标位置的 API *******************************
我爱的人Private Declare Function GetCursorPos Lib "ur32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
'*************************************************************************
Private Sub Form_Load()
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
Dim Point As POINTAPI长城的历史故事
GetCursorPos Point
Me.Caption = Point.X & " " & Point.Y
End Sub
3.动画鼠标
'添加 Picture1
Option Explicit
Private Const GCL_HCURSOR& = (-12)
Private Declare Function SetClassLong& Lib "ur32" Alias "SetClassLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Private Declare Function LoadCursorFromFile& Lib "ur32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String)
Private NewCursor1 As Long
Private OldCursor1 As Long
Private NewCursor2 As Long
Private OldCursor2 As Long
Dim appdisk$, winpath$
Private Sub Form_Load()
appdisk = Trim(App.Path)
If Right(appdisk, 1) <> "\" Then appdisk = appdisk & "\"
winpath = Environ("windir") 'windows系统路径
油冬菜
NewCursor1 = LoadCursorFromFile(winpath & "\cursors\appstart.ani") 'windows的cursors自带的.ani
OldCursor1 = SetClassLong(Me.hWnd, GCL_HCURSOR, NewCursor1)
NewCursor2 = LoadCursorFromFile(appdisk & "dinol.ani")
OldCursor2 = SetClassLong(Picture1.hWnd, GCL_HCURSOR, NewCursor2)
End Sub
Private Sub Form_Unload(Cancel As Integer)
SetClassLong Me.hWnd, GCL_HCURSOR, OldCursor1通知公告模板
SetClassLong Picture1.hWnd, GCL_HCURSOR, OldCursor2
End Sub
4.模拟点击鼠标
'添加 Command1 Command2 Command3
Option Explicit
'*********************************************************************************
Private Declare Function SetCursorPos Lib "ur32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Sub mou_event Lib "ur32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
'*********************************************************************************
Dim x1&, y1&
Private Sub Form_Load()
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2 '窗体置于屏幕中心
Command1.Caption = "模拟点左键"
Command2.Caption = "模拟点右键"
End Sub
Private Sub Command1_Click()
x1 = (Me.Left + Command3.Left + Command3.Width / 2) \ 15
y1 = (Me.Top + Command3.Top + Command3.Height / 2 + 405) \ 15
SetCursorPos x1, y1广州牙雕
mou_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
Private Sub Command2_Click()
x1 = (Me.Left + Command3.Left + Command3.Width / 2) \ 15
y1 = (Me.Top + Command3.Top + Command3.Height / 2 + 405) \ 15
SetCursorPos x1, y1
mou_event MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
End Sub
Private Sub Command3_MouDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
MsgBox "您点击了右键"
El
MsgBox "您点击了左键"
End If
你来看此花时End Sub
5.模拟鼠标移动
'添加 Command1
Option Explicit
'********************************* 时间延迟的 API ***************************
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliconds As Long)
'********************************* 设置鼠标位置的 API ***********************
Private Declare Function SetCursorPos Lib "ur32" (ByVal X As Long, ByVal Y As Long) As Long
'****************************************************************************
Dim x1&, y1&, x2&, y2&
Private Sub Form_Load()
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2 '窗体置于屏幕中心
'将Command1置于窗体中心
Command1.Move (Me.ScaleWidth - Command1.Width) \ 2, (Me.ScaleHeight - Command1.Height) \ 2
Command1.Caption = "模拟鼠标移动"
x1 = (Me.Left + Command1.Left + Command1.Width / 2 + 60) \ 15
y1 = (Me.Top + Command1.Top + Command1.Height / 2 + 405) \ 15
SetCursorPos x1, y1 '将鼠标移动到 Command1上面
End Sub
Private Sub Command1_Click()
蜡笔小新语录
Randomize
x1 = Int(Rnd * (Screen.Width \ 15))