当前位置:首页 > 程序设计 > VB程序设计 > 游戏辅助 > 详细内容
Spy++ 结合VB简单应用02010107-03源码
作者:潇潇  发布时间:2009-12-6  阅读次数:3280  字体大小: 【】 【】【
教学课题:SPY++ 结合VB简单应用之模拟鼠标操作(动作)
教学要点:VB编程坏境,以计算器为例模拟鼠标输入QQ号:854487915
教学步骤:1、认识API函数:mouse_event
Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)mouse_event模拟鼠标),无返回值;
参数一:操作标志,类型:Long
MOUSEEVENTF_MOVE  移动鼠标
MOUSEEVENTF_LEFTDOWN  模拟鼠标左键按下
MOUSEEVENTF_LEFTUP  模拟鼠标左键弹起
MOUSEEVENTF_RIGHTDOWN  模拟鼠标右键按下
MOUSEEVENTF_RIGHTUP  模拟鼠标右键弹起
MOUSEEVENTF_MIDDLEDOWN  模拟鼠标中键按下
MOUSEEVENTF_MIDDLEUP  模拟鼠标中键弹起
参数二:目标坐标X,类型:Long
参数三:目标坐标Y,类型:Long
参数四:数据信息,类型:Long,通常设置为0
参数五:扩展数据信息,类型:Long,通常设置为0

2、利用API函数mouse_event,实现模拟鼠标输入数字“8”。

教学代码:

'API声明
'=========================================
'查找窗口
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'设置指针位置或设置目的坐标
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
'取窗口矩形范围坐标
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) 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 Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Type RECT '目标窗口矩形范围坐标结构
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Const MOUSEEVENTF_LEFTDOWN = &H2 '   鼠标左键按下
Private Const MOUSEEVENTF_LEFTUP = &H4     '   鼠标左键弹起

Private Sub Command1_Click()
Dim ck_hwnd As Long     '定义计算器窗口句柄变量
ck_hwnd = FindWindow("SciCalc", "计算器") 'SciCalc 取计算器窗口句柄
Text1.Text = Str(ck_hwnd)
Dim ck_R As RECT
If ck_hwnd <> 0 Then
       GetWindowRect ck_hwnd, ck_R   ' 取计算器窗口矩形范围坐标,或左上角坐标及右下角坐标
       Label2.Caption = Str(ck_R.Left) & Str(ck_R.Top) & Str(ck_R.Right) & Str(ck_R.Bottom)
       SetCursorPos 350 + ck_R.Left, 150 + ck_R.Top '设置鼠标指针
       Sleep (100)
       mouse_event MOUSEEVENTF_LEFTDOWN, 350 + ck_R.Top, 150 + ck_R.Top, 0, 0
       Sleep (50)
       mouse_event MOUSEEVENTF_LEFTUP, 350 + ck_R.Top, 150 + ck_R.Top, 0, 0
End If
End Sub

来源:潇潇的编程网站
我要评论
  • 匿名发表
  • [添加到收藏夹]
  • 发表评论:(匿名发表无需登录,已登录用户可直接发表。) 登录状态:未登录
最新评论
所有评论[0]
    暂无已审核评论!
Web Lite SWeTE: Simple Website Translation Engine
 


设为首页 | 加入收藏 | 意见建议 | 友情链接 | 版权声明 | 管理登陆 | 编程论坛 | 给我留言

声明:本网站部分稿件来源的所有文字、图片和音视频稿件,来自互联网,若侵犯您的权利,请来信告知,我们将在第一时间内删除!


Copyright 2009-2015 redrose ( wgbcw.cn ) All rights reserved ICP备案编号:滇ICP备09007156号 Dict.cn


点击这里给我发消息
点击这里给我发消息
安全联盟站长平台