云南招生考试信息网→ynexam.COM→※云南考试网※云南人事考试网※云南省公务员考试网※云南专升本考试报名※云南考试培训认证网※云南考试中心网
云南招生考试第一咨讯平台
首页 校园 网上书店  研考招生  普高招生 成考招生 自考招生 中考招生 教师资格 公务员考试 事业单位 人才招聘 留言
人力资源 | 秘书 | 物流师 | 营销师 | 会计证 | 导游 | 医药考试 | 建筑考试 | 外贸考试 | 电脑认证 | 外语考试 | 司法考试
心理咨询师| 职业指导师 | 理财规划师| 电子商务 | 项目管理 | 物业管理 | 报关员 | 营养师 | 美容美发 | 驾校 | 培训| 动态
 
 
当前位置:首页 > 云南计算机等级考试网 > 正文
如何自动移动Mouse
来源: 时间:2008-05-26

事实上是使用SetCursorPos()便可以了,而它的参数是对应於萤的座标,而不是对应某一个Window的Logic座标。这个例子中的MoveCursor()所传入的POINTAPI也是相对於萤屏的座标,指的是从点FromP移动到ToP。最後面我也付了Showje的文章,使用的方式全部不同,不管是他的或我的,都有一个地方要解决才能做为Mouse自动导引的程式,那就是Mouse在自动Move时,如何让使用者不能移动Mouse,而这个问题就要使用JournalPlayBack Hook,底下的程式中,使用 EnableHook, FreeHook,这两个函数是Copy自如何使键盘、Mouse失效 。
  '以下程式在.bas
  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

  Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
  Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
  Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

  Public Sub MoveCursor(FromP As POINTAPI, ToP As POINTAPI)
  Dim stepx As Long, stepy As Long, k As Long
  Dim i As Long, j As Long, sDelay As Long
  stepx = 1
  stepy = 1
  i = (ToP.X - FromP.X)
  If i < 0 Then stepx = -1
  i = (ToP.Y - FromP.Y)
  If i < 0 Then stepy = -1
  'Call EnableHook '如果有Include htmapi53.htm的.bas时,会Disable Mouse
  For i = FromP.X To ToP.X Step stepx
  Call SetCursorPos(i, FromP.Y)
  Sleep (1) '让Mouse 的移动慢一点,这样效果较好
  Next i
  For i = FromP.Y To ToP.Y Step stepy
  Call SetCursorPos(ToP.X, i)
  Sleep (1)
  Next i
  'Call FreeHook 'Enable Mouse
  End Sub
  '以下程式在Form中,需3个Command按键
  Private Sub Command3_Click()
  Dim rect5 As RECT
  Dim p1 As POINTAPI, p2 As POINTAPI
  Call GetWindowRect(Command1.hwnd, rect5) '取得Command1相对於Screen的座标
  p1.X = (rect5.Left + rect5.Right) \ 2
  p1.Y = (rect5.ToP + rect5.Bottom) \ 2
  Call GetWindowRect(Command2.hwnd, rect5)
  p2.X = (rect5.Left + rect5.Right) \ 2
  p2.Y = (rect5.ToP + rect5.Bottom) \ 2

  Call MoveCursor(p1, p2) 'Mouse由Command1 ->Command2
  End Sub

  另外从Showje的站有Copy以下的程式码,也是做相同的果,只是使用的API全部不同

  '以下程式在Form中,需2个Command按键
  '以下置於form的一般宣告区
  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 Declare Function ClientToScreen Lib "user32" _
  ( _
  ByVal hwnd As Long, _
  lpPoint As POINTAPI _
  ) As Long

  Private Declare Function GetSystemMetrics Lib "user32" _
  ( _
  ByVal nIndex As Long _
  ) As Long
  Private Declare Function GetCursorPos Lib "user32" _
  ( _
  lpPoint As POINTAPI _
  ) As Long

Private Type POINTAPI
  x As Long
  y As Long
  End Type

  Private Type OSVERSIONINFO
  dwOSVersionInfoSize As Long
  dwMajorVersion As Long
  dwMinorVersion As Long
  dwBuildNumber As Long
  dwPlatformId As Long
  szCSDVersion As String * 128
  End Type


  Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move
  Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
  Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
  Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move


  Private Sub Command1_Click()

  Dim pt As POINTAPI
  Dim dl&
  Dim destx&, desty&, curx&, cury&
  Dim distx&, disty&
  Dim screenx&, screeny&
  Dim finished%
  Dim ptsperx&, ptspery&

  pt.x = 10
  pt.y = 10
  dl& = ClientToScreen(Command2.hwnd, pt)

  screenx& = GetSystemMetrics(0) '0表x轴

  screeny& = GetSystemMetrics(1) '1表y轴

  destx& = pt.x * &HFFFF& / screenx&
  desty& = pt.y * &HFFFF& / screeny&


  ptsperx& = &HFFFF& / screenx&
  ptspery& = &HFFFF& / screeny&

  ' Now move it
  Do
  dl& = GetCursorPos(pt)
  curx& = pt.x * &HFFFF& / screenx&
  cury& = pt.y * &HFFFF& / screeny&
  distx& = destx& - curx&
  disty& = desty& - cury&
  If (Abs(distx&) < 2 * ptsperx& And Abs(disty&) < 2 * ptspery) Then
  ' Close enough, go the rest of the way
  curx& = destx&

本文:如何自动移动Mouse
共2页: 上一页 1 [2] 下一页
上一篇:注册会计师考试2000年《会计》试题及答案
下一篇:用VisualC#实现文件大批量处理
[返回顶部] [打印本页] [关闭窗口]  
招生信息
·2009年云南省普通类专升本考试辅导
·2009年云南省人力资源管理师资格全
·2009年国家职业资格物流师全国统一
·2009年云南省秘书资格全国统一鉴定
·2009年云南昆明市普通话水平测试简
·2009年云南教师资格证考试培训通知
·云南2008年公务员面试培训课程安排
·2009年云南省普通类专升本考试培训
·[最后一期]:云南公务员培训8月9日
·[基础班]7月26日公务员培训云大开
·7月17日公务员培训云南大学开班
·翡翠(宝玉石)鉴别与营销课程高级
·云南08法检公务员培训班
·7月5日全天公务员培训云南大学开班
·08年云南教师资格证考试培训报名
·5月3日公务员辅导班公告
·云南公务员考前辅导班3月22日开班
·2008年国家职业资格物流师全国统一
·云南2008年公务员考试培训班全年计
·2008昆明市全国普通话水平测试考前
最新资讯
版权所有·云南招生考试信息网 滇ICP备06005811号
Copygight © 2007-2008 www.ynexam.com All Rights Reserved.
主办单位:云南招生考试信息网 指导单位:云南互联网联盟协会
技术维护:云南招生考试信息网网络中心 法律顾问:梦想成真律师事务所