VB6.0鼠标点击移动操作程序代码

'sleep函数
Private Declare Sub Sleep Lib “kernel32” (ByVal dwMilliseconds As Long)

'获取鼠标坐标
Private Type POINTAPI
X As Long
Y As Long

End Type
Private Declare Function GetCursorPos Lib “user32” (lpPoint As POINTAPI) As Long

'移动鼠标
Private Declare Function SetCursorPos Lib “user32” (ByVal X As Long, ByVal Y As Long) As Long
Private 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)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_RIGHTDOWN = &H8
Private Const MOUSEEVENTF_RIGHTUP = &H10

Private Declare Function SetCapture Lib “user32” (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib “user32” () As Long

Private Declare Function PostMessage Lib “user32” Alias “PostMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_MOUSEMOVE As Long = &H200 ’ 鼠标移动消息
Private Const WM_LBUTTONDOWN As Long = &H201 ’ 左键按下消息
Private Const WM_LBUTTONUP As Long = &H202 ’ 左键松开消息

Private Sub Command2_Click()
Dim i, j As String

i = Text2.Text
j = Text3.Text

SetCursorPos i, j

mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 500

SetCursorPos i - 400, j ’ 向左移动鼠标到指定位置

Sleep 800

SetCursorPos i + 400, j ’ 向右移动鼠标到指定位置

Sleep 800






  SetCursorPos i, j - 400  ' 向上移动鼠标到指定位置

Sleep 800

 

    
  SetCursorPos i, j + 400  ' 向下移动鼠标到指定位置

Sleep 800

 




mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

Sleep 500

End Sub

Private Sub Command3_Click()

Dim i, j, k, l, m, n As String

i = Text2.Text
j = Text3.Text

k = Text5.Text
l = Text6.Text

m = Text1.Text
n = Text7.Text

For a = 0 To 3

SetCursorPos i, j

mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 500

SetCursorPos i + 300, j ’ 向右移动鼠标到指定位置

Sleep 500


mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

Sleep 500

Next

End Sub

Private Sub Command6_Click()
Dim m, n As String

m = Text1.Text
n = Text7.Text

SetCursorPos m, n

mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

End Sub

Private Sub Command1_Click()
Dim i, j As String

i = Text2.Text
j = Text3.Text

SetCursorPos i, j

mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 500

SetCursorPos i - 600, j ’ 向左移动鼠标到指定位置

Sleep 800

SetCursorPos i + 600, j ’ 向右移动鼠标到指定位置

Sleep 800






  SetCursorPos i, j - 300  ' 向上移动鼠标到指定位置

Sleep 800

 

    
  SetCursorPos i, j + 300  ' 向下移动鼠标到指定位置

Sleep 800

 




mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

Sleep 500

End Sub

Private Sub Command4_Click()
Dim k, l As String

k = Text5.Text
l = Text6.Text

SetCursorPos k, l

mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 500

SetCursorPos k, l - 500 ’ 向上移动鼠标到指定位置

Sleep 500


mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

Sleep 500

End Sub

Private Sub Timer1_Timer()
Dim POINT As POINTAPI
GetCursorPos POINT
Label1.Caption = “鼠标坐标:” & vbCrLf & vbCrLf & “鼠标横坐标为:” & POINT.X & vbCrLf & “鼠标纵坐标为:” & POINT.Y

End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

EasySoft易软

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值