当前位置:首页 > 程序设计 > VB程序设计 > 游戏辅助 > 详细内容
SPY++ 结合VB简单应用02010108-02优化源码
作者:潇潇  发布时间:2009-12-6  阅读次数:3524  字体大小: 【】 【】【
教学课题:SPY++ 结合VB简单应用之代码优化
教学要点:VB编程坏境,以计算器为例模拟鼠标输入QQ号:854487915
教学步骤:简化“mouse_event”函数
教学源码:

Form窗体:

Private Sub Command1_Click()
Dim ck_hwnd As Long     '定义计算器窗口句柄变量
'ck_hwnd = FindWindow(vbNullString, "计算器") 'SciCalc 取计算器窗口句柄
ck_hwnd = FindWindow("SciCalc", vbNullString)
Text1.Text = Str(ck_hwnd)
Dim ck_R As RECT
If ck_hwnd <> 0 Then

       GetWindowRect ck_hwnd, ck_R   ' 取计算器窗口矩形范围坐标,或左上角坐标及右下角坐标
      
       '按下数字键8
       Sleep (100)
       SetCursorPos 350 + ck_R.Left, 150 + ck_R.Top '设置鼠标指针
       M_LeftDown 350 + ck_R.Left, 150 + ck_R.Top
       Sleep (50)
       M_LeftUp 350 + ck_R.Left, 150 + ck_R.Top
       '按下数字键5
       Sleep (100)
       SetCursorPos 350 + ck_R.Left, 180 + ck_R.Top '设置鼠标指针
       M_LeftDown 350 + ck_R.Left, 180 + ck_R.Top
       Sleep (50)
       M_LeftUp 350 + ck_R.Left, 180 + ck_R.Top
      
       '按下数字键4
       Sleep (100)
       SetCursorPos 308 + ck_R.Left, 180 + ck_R.Top '设置鼠标指针
       M_LeftDown 308 + ck_R.Left, 180 + ck_R.Top
       Sleep (50)
       M_LeftUp 308 + ck_R.Left, 180 + ck_R.Top
      
       '按下数字键4
       Sleep (100)
       SetCursorPos 308 + ck_R.Left, 180 + ck_R.Top '设置鼠标指针
       M_LeftDown 308 + ck_R.Left, 180 + ck_R.Top
       Sleep (50)
       M_LeftUp 308 + ck_R.Left, 180 + ck_R.Top
      
       '按下数字键8
       Sleep (100)
       SetCursorPos 350 + ck_R.Left, 150 + ck_R.Top '设置鼠标指针
       M_LeftDown 350 + ck_R.Left, 150 + ck_R.Top
       Sleep (50)
       M_LeftUp 350 + ck_R.Left, 150 + ck_R.Top
      
       '按下数字键7
       Sleep (100)
       SetCursorPos 308 + ck_R.Left, 150 + ck_R.Top '设置鼠标指针
       M_LeftDown 308 + ck_R.Left, 150 + ck_R.Top
       Sleep (50)
       M_LeftUp 308 + ck_R.Left, 150 + ck_R.Top
      
       '按下数字键9
       Sleep (100)
       SetCursorPos 385 + ck_R.Left, 150 + ck_R.Top '设置鼠标指针
       M_LeftDown 385 + ck_R.Left, 150 + ck_R.Top
       Sleep (50)
       M_LeftUp 385 + ck_R.Left, 150 + ck_R.Top
      
       '按下数字键1
       Sleep (100)
       SetCursorPos 308 + ck_R.Left, 210 + ck_R.Top '设置鼠标指针
       M_LeftDown 308 + ck_R.Left, 210 + ck_R.Top
       Sleep (50)
       M_LeftUp 308 + ck_R.Left, 210 + ck_R.Top
      
       '按下数字键5
       Sleep (100)
       SetCursorPos 350 + ck_R.Left, 180 + ck_R.Top '设置鼠标指针
       M_LeftDown 350 + ck_R.Left, 180 + ck_R.Top
       Sleep (50)
       M_LeftUp 350 + ck_R.Left, 180 + ck_R.Top
End If
End Sub


ModAPI:

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

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

'dx和dy指定鼠标坐标系统中的一个绝对位置。在鼠标坐标系统中,屏幕在水平和垂直方向上均匀分割成65535×65535个单元
'Public Const MOUSEEVENTF_ABSOLUTE = &H8000
'Public Const MOUSEEVENTF_MOVE = &H1               '   移动鼠标
'Public Const MOUSEEVENTF_LEFTDOWN = &H2     '   鼠标左键按下
'Public Const MOUSEEVENTF_LEFTUP = &H4         '   鼠标左键弹起
'Public Const MOUSEEVENTF_RIGHTDOWN = &H8     '   模拟鼠标右键按下
'Public Const MOUSEEVENTF_RIGHTUP = &H10       '   模拟鼠标右键弹起
'Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 '   模拟鼠标中键按
'Public Const MOUSEEVENTF_MIDDLEUP = &H40     '   模拟鼠标中键弹起

ModAPIJh:
'API函数简化
'=========================
'鼠标左键按下子程序
Sub M_LeftDown(dx As Long, dy As Long)
       'mouse_event MOUSEEVENTF_LEFTDOWN, dx, dy, 0, 0
       mouse_event 2, dx, dy, 0, 0
End Sub
'鼠标左键弹起子程序
Sub M_LeftUp(dx As Long, dy As Long)
       'mouse_event MOUSEEVENTF_LEFTUP, dx, dy, 0, 0
       mouse_event 4, dx, dy, 0, 0
End Sub

来源:潇潇的编程网站
上一篇:SPY++ 结合VB简单应用02010108-01优化源码 下一篇:没有了!
我要评论
  • 匿名发表
  • [添加到收藏夹]
  • 发表评论:(匿名发表无需登录,已登录用户可直接发表。) 登录状态:未登录
最新评论
所有评论[2]
    暂无已审核评论!
Web Lite SWeTE: Simple Website Translation Engine
 


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

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


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


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