• 网络学院
  • IT资讯
  • 操作系统
  • 网络技术
  • 软件应用
  • 办公软件
  • 编程技术
  • 网站架设
  • 数据库类
  • 平面设计
  • 多媒体类
  • 游戏资讯
  • 教学论文
  • 认证考试
如何使用程序自动移动Mouse
  站点:
  • 首 页
  • 最新软件
  • 文章教程
  • 国内软件
  • 国外软件
  • 绿色软件
  • 源码下载
  • 字体下载
如何使用程序自动移动Mouse
软件发布 如何使用程序自动移动Mouse
网络软件 系统工具 应用软件 联络聊天 图形图像 多媒体类 行业软件 游戏娱乐 编程开发 安全相关 教育教学 数码软件 绿软下载
热门软件: QQ 瑞星 pplive e话通 木马克星 千千静听 office2000 五笔字根 Photoshop 视频分割
返回文章教程首页 >> 文章首页 >> 编程技术 >> VB & VB.NET教程 >> 如何使用程序自动移动Mouse

如何使用程序自动移动Mouse

添加时间: 2006-2-16 5:45:32  作者: VB教程  阅读次数:84   来源: http://www.d9soft.com

        事实上是使用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&
cury& = desty&
finished% = True
Else
' Move closer
curx& = curx& + Sgn(distx&) * ptsperx * 2
cury& = cury& + Sgn(disty&) * ptspery * 2
End If
mouse_event MOUSEEVENTF_ABSOLUTE _
Or MOUSEEVENTF_MOVE, curx, cury, 0, 0
Loop While Not finished

' 到家了,按上右键吧!注:是左键,Showje的笔误
'以下是在(curx, cury)的座标下,模拟Mouse 左键的down and up
mouse_event MOUSEEVENTF_ABSOLUTE Or _
MOUSEEVENTF_LEFTDOWN, curx, cury, 0, 0

mouse_event MOUSEEVENTF_ABSOLUTE Or _
MOUSEEVENTF_LEFTUP, curx, cury, 0, 0

End Sub

Private Sub Command2_Click()
MsgBox "看你往哪儿逃!哈!!"
End Sub

 

上下文章:

 

上一篇文章: Visual Basic6.0实用编程技巧3例 下一篇文章: 在VB中判断Windows9x的运行模式

相关文章:

  • 教你如何用零框架技术加密网页
  • PS教程:看看如何用Photoshop把照片演变成水墨画
  • Photoshop教程:教你如何创出发丝的炫彩莹亮效果
  • 魔兽世界:如何更大限度的利用奥冲循环
  • 教你如何用PhotoImpact 来制作逼真的温度计

相关软件:

  • Mouse Tamer V2.0
  • 哑巴鼠标自动点击器 V2.3
  • 全国计算机等级考试模拟软件(2006年全年使用)二级Visual Basic V9.0
  • FTP远程文件同步更新程序 1.0.0.0
  • 围棋死活习题集移动版之PocketPC 2003版 1.0
  • 围棋死活习题集移动版之Palm版 1.0

 

快速导航

  • 网络学院
  • 精品汇聚
  • 字体下载
  • 教程下载
  • ASP源码
  • PHP源码
  • Net源码
  • JSP 源码

编程技术分类导航

  • ASP & ASP.NET教程
  • PHP教程
  • JSP教程
  • C/C++教程
  • VB & VB.NET教程
  • VC教程
  • Delphi教程
  • BCB教程
  • VFP教程
  • PB教程
  • JAVA教程
  • XML教程
  • C#教程
  • CGI教程

本类经典文章推荐

  • C++程序设计之四书五经
  • VB入门教程之四
  • VB入门教程之三
  • VB入门教程之二
  • VB入门教程之一
  • 压缩被DBGIRD控件正在使用的MDB数...
  • 谈谈VB的数据库编程方式
  • 在VB中用DAO实现数据库编程
  • Data控件使用有密码的Access数据库
  • 用DAO或ADO正确访问Access 2000

VB & VB.NET教程阅读排行

  • VB入门教程之一
  • VB入门教程之二
  • VB入门教程之三
  • VB入门教程之四
  • 如何编写高质量的VB代码
  • 初学者必知:VB10个小编程
  • VB访问SQL Server数据库技术全揭密
  • 怎样在VB中控制Word?
  • 用DAO或ADO正确访问Access 2000
  • VB中列表框的使用技巧说明

编程技术阅读总排行

  • VB入门教程之一
  • Java连接数据库实例
  • 第二章 PowerBuilder 入门之创建新...
  • VC++之List Box/Check List Box控...
  • 第一章 什么是PowerBuilder
  • VC++ List Ctrl控件
  • VC++ Combo Box/Combo Box Ex控件
  • 学C++不得不看的一篇文章
  • VB入门教程之二
  • VC++之Button控件

广告位置

字母检索 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 回到顶部

关于我们 | 版权声明 | 免责条款 | 广告联系 | 软件发布 | 下载帮助 | 下载排行 | 网站地图 | 特别鸣谢 | 友情连接

copyright; 2005-2008 D9soft.com 第九软件网 版权所有