求个“鼠标定时自动点击”的代码

hyjia 2009-11-07 03:57:48
屏幕上一块区域,从左到右,鼠标可以每隔30秒点击一下,谢谢,急用,以前学的东西没用就忘记了,多谢!
...全文
1757 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2009-11-09
  • 打赏
  • 举报
回复
AutoHotKey
贝隆 2009-11-07
  • 打赏
  • 举报
回复
如何限制鼠标在窗口的指定范围内移动

操作步骤
1、建立一个新工程项目,缺省建立窗体FORM1
2、添加一个新模体
3、粘贴下面代码到新模体

Option ExplicitDeclare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Declare Function ClipCursorClear Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long) As Long
Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Type POINTAPI
X As Long
Y As Long
End Type
Public RetValue As Long
Public ClipMode As Boolean


Public Sub SetCursor(ClipObject As Object, Setting As Boolean)
' used to clip the cursor into the viewport and
' turn off the default windows cursor


Dim CurrentPoint As POINTAPI
Dim ClipRect As RECT


If Setting = False Then
' set clip state back to normal
RetValue = ClipCursorClear(0)
Exit Sub
End If


' set current position
With CurrentPoint
.X = 0
.Y = 0
End With
' find position on the screen (not the window)
RetValue = ClientToScreen(ClipObject.hwnd, CurrentPoint)
' designate clip area
With ClipRect
.Top = CurrentPoint.Y
.Left = CurrentPoint.X
.Right = .Left + ClipObject.ScaleWidth
.Bottom = .Top + ClipObject.ScaleHeight
End With ' clip it
RetValue = ClipCursor(ClipRect)


End Sub


4、添加一个图片框控件(PICTURE1)到窗体(FORM1)
5、设置PICTURE1的尺寸和FORM1的一样大
6、在PICTURE1的CLICK事件中添加以下代码:


Private Sub Picture1_Click()
ClipMode = Not ClipMode
SetCursor Picture1, ClipMode
End Sub


7、保存工程项目
8、运行程序。
贝隆 2009-11-07
  • 打赏
  • 举报
回复
思路:
1、限定鼠标在指定的区域
2、在定时器中定时触发鼠标单击事件
3、使用mouse_event模拟鼠标单击事件。

SYSSZ 2009-11-07
  • 打赏
  • 举报
回复
'测试时用的是6秒,改为
If t Mod 10 = 0 Then就是30秒点击1次了
SYSSZ 2009-11-07
  • 打赏
  • 举报
回复

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_ABSOLUTE = &H8000 '指定鼠标使用绝对坐标系,此时,屏幕在水平和垂直方向上均匀分割成65535×65535个单元
Private Const MOUSEEVENTF_MOVE = &H1 '移动鼠标
Private Const MOUSEEVENTF_LEFTDOWN = &H2 '模拟鼠标左键按下
Private Const MOUSEEVENTF_LEFTUP = &H4 '模拟鼠标左键抬起
Private i As Integer
Private Const SW = 1024
Private Const SH = 768

Private Sub Screen_Click(ByVal x As Long, ByVal y As Long)
mw = x / SW * 65535
mh = y / SH * 65535
mouse_event MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE, mw, mh, 0, 0
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub

Private Sub Form_Load()
Timer1.Interval = 3000
End Sub

Private Sub Timer1_Timer()
Static t As Long
If i > 1024 Then i = 0
t = t + 1
If t Mod 2 = 0 Then
Screen_Click i, 200
Debug.Print i
i = i + 100
End If
End Sub
cBirdNO1NO1 2009-11-07
  • 打赏
  • 举报
回复
定时给窗口发送鼠标单击消息
zzhgb 2009-11-07
  • 打赏
  • 举报
回复
sendmessage
WM_click
舉杯邀明月 2009-11-07
  • 打赏
  • 举报
回复
Timer 控件 + API :
mouse_event()

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧