当前位置:首页 > 程序设计 > VB程序设计 > 游戏辅助 > 详细内容
SPY++ 结合VB简单应用02010108-01优化源码
作者:潇潇  发布时间:2009-12-6  阅读次数:3294  字体大小: 【】 【】【
教学课题:SPY++ 结合VB简单应用之代码优化
教学要点:VB编程坏境,以计算器为例模拟鼠标输入QQ号:854487915
教学步骤:1、引入模块实例.bas
                               2、简化“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 '设置鼠标指针
       'mouse_event MOUSEEVENTF_LEFTDOWN, 350 + ck_R.Left, 150 + ck_R.Top, 0, 0
       LeftDown 350 + ck_R.Left, 150 + ck_R.Top

       Sleep (50)
       'mouse_event MOUSEEVENTF_LEFTUP, 350 + ck_R.Left, 150 + ck_R.Top, 0, 0
       LeftUp 350 + ck_R.Left, 150 + ck_R.Top
       '按下数字键5
       Sleep (100)
       SetCursorPos 350 + ck_R.Left, 180 + ck_R.Top '设置鼠标指针
       mouse_event MOUSEEVENTF_LEFTDOWN, 350 + ck_R.Left, 180 + ck_R.Top, 0, 0
       Sleep (50)
       mouse_event MOUSEEVENTF_LEFTUP, 350 + ck_R.Left, 180 + ck_R.Top, 0, 0
      
       '按下数字键4
       Sleep (100)
       SetCursorPos 308 + ck_R.Left, 180 + ck_R.Top '设置鼠标指针
       mouse_event MOUSEEVENTF_LEFTDOWN, 308 + ck_R.Left, 180 + ck_R.Top, 0, 0
       Sleep (50)
       mouse_event MOUSEEVENTF_LEFTUP, 308 + ck_R.Left, 180 + ck_R.Top, 0, 0
      
       '按下数字键4
       Sleep (100)
       SetCursorPos 308 + ck_R.Left, 180 + ck_R.Top '设置鼠标指针
       mouse_event MOUSEEVENTF_LEFTDOWN, 308 + ck_R.Left, 180 + ck_R.Top, 0, 0
       Sleep (50)
       mouse_event MOUSEEVENTF_LEFTUP, 308 + ck_R.Left, 180 + ck_R.Top, 0, 0
      
       '按下数字键8
       Sleep (100)
       SetCursorPos 350 + ck_R.Left, 150 + ck_R.Top '设置鼠标指针
       mouse_event MOUSEEVENTF_LEFTDOWN, 350 + ck_R.Left, 150 + ck_R.Top, 0, 0
       Sleep (50)
       mouse_event MOUSEEVENTF_LEFTUP, 350 + ck_R.Left, 150 + ck_R.Top, 0, 0
      
       '按下数字键7
       Sleep (100)
       SetCursorPos 308 + ck_R.Left, 150 + ck_R.Top '设置鼠标指针
       mouse_event MOUSEEVENTF_LEFTDOWN, 308 + ck_R.Left, 150 + ck_R.Top, 0, 0
       Sleep (50)
       mouse_event MOUSEEVENTF_LEFTUP, 308 + ck_R.Left, 150 + ck_R.Top, 0, 0
      
       '按下数字键9
       Sleep (100)
       SetCursorPos 385 + ck_R.Left, 150 + ck_R.Top '设置鼠标指针
       mouse_event MOUSEEVENTF_LEFTDOWN, 385 + ck_R.Left, 150 + ck_R.Top, 0, 0
       Sleep (50)
       mouse_event MOUSEEVENTF_LEFTUP, 385 + ck_R.Left, 150 + ck_R.Top, 0, 0
      
       '按下数字键1
       Sleep (100)
       SetCursorPos 308 + ck_R.Left, 210 + ck_R.Top '设置鼠标指针
       mouse_event MOUSEEVENTF_LEFTDOWN, 308 + ck_R.Left, 210 + ck_R.Top, 0, 0
       Sleep (50)
       mouse_event MOUSEEVENTF_LEFTUP, 308 + ck_R.Left, 210 + ck_R.Top, 0, 0
      
       '按下数字键5
       Sleep (100)
       SetCursorPos 350 + ck_R.Left, 180 + ck_R.Top '设置鼠标指针
       mouse_event MOUSEEVENTF_LEFTDOWN, 350 + ck_R.Left, 180 + ck_R.Top, 0, 0
       Sleep (50)
       mouse_event MOUSEEVENTF_LEFTUP, 350 + ck_R.Left, 180 + ck_R.Top, 0, 0
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

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


ModAPIJh:

'API函数简化
Sub LeftDown(dx As Long, dy As Long)
mouse_event MOUSEEVENTF_LEFTDOWN, dx, dy, 0, 0
End Sub

Sub LeftUp(dx As Long, dy As Long)
mouse_event MOUSEEVENTF_LEFTUP, dx, dy, 0, 0
End Sub

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


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

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


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


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