| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 566 人关注过本帖
标题:求大神帮我提下速度
只看楼主 加入收藏
compdnycdke
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-10-14
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
求大神帮我提下速度
以下程序在运行的时候鼠标移动的不连贯,走下停下很明显,求大神修改连贯的移动
Do
重新找鼠标颜色:
  
    Dim i, ii, ttt, zX, zY, ppp, pp, qqq, qq, zzX, zzY, ux, uy, Screenx, Screeny As Long
    Dim p() As Long
    Dim Q() As Long
    Dim hmemDC As Long, hmemBMP As Long, bmp_info As BITMAPINFO, lpBits As Long
    Dim dwX As Long, dwY As Long
    Dim PicData() As Byte
    Dim ScreenDC As Long
    Dim TargetColor As Long
    Dim crColor As RGBCOLOR
i = 0
TargetColor = &H68E8E8 '为游戏鼠标的特征颜色值16进制
    CopyMemory crColor, TargetColor, 4
    ScreenDC = GetDC(0)
    With bmp_info.bmiHeader
        .biSize = LenB(bmp_info.bmiHeader)
        .biWidth = Screen.Width / Screen.TwipsPerPixelX
        .biHeight = Screen.Height / Screen.TwipsPerPixelY
        .biPlanes = 1
        .biBitCount = 32
        .biCompression = BI_RGB
        .biSizeImage = .biHeight * (((.biWidth * .biBitCount + 31) And &HFFFFFFE0) \ 8)
    End With
     
    hmemDC = CreateCompatibleDC(ScreenDC)
    hmemBMP = CreateDIBSection(ScreenDC, bmp_info, DIB_RGB_COLORS, lpBits, 0, 0)
    SelectObject hmemDC, hmemBMP
     
    BitBlt hmemDC, 0, 0, bmp_info.bmiHeader.biWidth, bmp_info.bmiHeader.biHeight, ScreenDC, 0, 0, vbSrcCopy
     
    ReDim PicData(3, bmp_info.bmiHeader.biWidth - 1, bmp_info.bmiHeader.biHeight - 1) As Byte
     
    CopyMemory PicData(0, 0, 0), ByVal lpBits, bmp_info.bmiHeader.biSizeImage

    'Debug.Print "查找坐标范围:(0,0) - (" & CStr(bmp_info.bmiHeader.biWidth - 1) & "," & CStr(bmp_info.bmiHeader.biHeight - 1) & ")"
    For dwY = 0 To bmp_info.bmiHeader.biHeight - 1
        For dwX = 0 To bmp_info.bmiHeader.biWidth - 1
            If (PicData(0, dwX, dwY) = crColor.rgbBlue) And (PicData(1, dwX, dwY) = crColor.rgbGreen) And (PicData(2, dwX, dwY) = crColor.rgbRed) Then
              'And (PicData(0, dwX+10, dwY-10) = crColor.rgbBlue) And (PicData(1, dwX+10, dwY-10) = crColor.rgbGreen) And (PicData(2, dwX+10, dwY-10) = crColor.rgbRed)
            'Debug.Print "找到目标颜色,坐标:" & CStr(dwX) & "," & CStr(bmp_info.bmiHeader.biHeight - dwY - 1)
            ReDim Preserve p(i)
            ReDim Preserve Q(i)
            p(i) = CStr(dwX)
            Q(i) = CStr(bmp_info.bmiHeader.biHeight - dwY - 1)
            i = i + 1
            End If
        Next
    Next
    'MsgBox "查找结束"
    DeleteDC hmemDC
    DeleteObject hmemBMP
    ReleaseDC 0, ScreenDC
   
   
'分析横纵坐标,找到满足点P,Q的坐标返回值是P的坐标“-705”和“-68”是2个坐标的差值
For i = 0 To i - 1
   For ii = 0 To i - 1
     If p(i) - 10 = p(ii) And Q(i) + 10 = Q(ii) Then
     'Debug.Print "坐标" & p(i) & "," & Q(i) & "和坐标" & p(ii) & "," & Q(ii)
     GoTo exitendfenxi:
     End If
   Next
Next
'Debug.Print "没有找到符合要求的坐标"
GoTo 重新找鼠标颜色:
exitendfenxi:
   
   
   
    zX = p(i) - 19
    zY = Q(i) - 10 '游戏鼠标坐标
    If zX > 0 Or zY > 0 Then
    zzX = zX
    zzY = zY
    Else
    zX = zzX
    zY = zzY
    Sleep 20
    End If
 If Abs(intX - zX) < 3 Then
    ppp = 0
 End If
 If Abs(intX - zX) > 20 Then
    Randomize
    ppp = Int(Rnd() * 3 + 5)
        If Abs(intX - zX) > Abs(intY - zY) Then
        ppp = ppp
        ElseIf Abs(intX - zX) < Abs(intY - zY) Then
        ppp = Int(ppp * (Abs(intX - zX) / Abs(intY - zY)))
        End If
    ElseIf 50 > Abs(intX - zX) Then
    ppp = 1
   
 End If
   
    If intX > zX Then
    pp = ppp
    ElseIf intX < zX Then
    pp = -ppp
    ElseIf Abs(intX - zX) < 3 Then
    pp = 0
End If


If Abs(intY - zY) < 3 Then
    qqq = 0
End If
 If Abs(intY - zY) > 20 Then
    Randomize
    qqq = Int(Rnd() * 3 + 5)
        If Abs(intX - zX) > Abs(intY - zY) Then
        qqq = Int(qqq * (Abs(intY - zY) / Abs(intX - zX)))
        ElseIf Abs(intX - zX) < Abs(intY - zY) Then
        qqq = qqq
        End If
    ElseIf 50 > Abs(intY - zY) Then
    qqq = 1
 End If
   
    If intY > zY Then
    qq = qqq
    ElseIf intY < zY Then
    qq = -qqq
    ElseIf Abs(intY - zY) < 3 Then
    qq = 0
End If

GetCursorPos moubegin
If moubegin.X > 650 Or moubegin.Y > 500 Or moubegin.X < 10 Or moubegin.Y < 10 Then
Randomize
MoveTo Int(Rnd() * 100 + 300), Int(Rnd() * 100 + 200)
Sleep 200
End If
mousestep = moubegin
SetCursorPos moubegin.X + pp, moubegin.Y + qq
Sleep 2
Loop While Abs(intY - zY) > 2 Or Abs(intX - zX) > 2
搜索更多相关主题的帖子: 鼠标 
2013-04-16 15:43
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:7 
没仔细研究流程,主要对一块也不是很熟。只提几个建议吧。

1、 Dim i, ii, ttt, zX, zY, ppp, pp, qqq, qq, zzX, zzY, ux, uy, Screenx, Screeny As Long
VB 与 C 不同,VB的变量申明必须明确指出每个变量的类型,而不能像 C 一样一个类型后面列出一堆变量名。

2、在程序运行过程中固定的值,可以定义为 常量 ,不需要每次都再去赋值。
TargetColor = &H68E8E8 '为游戏鼠标的特征颜色值16进制

3、对于固定值的操作,你可以直接定义为全局变量放在初始化的过程中,或者在定义为局部变量,在循环体外进行初始化。
    CopyMemory crColor, TargetColor, 4

    With bmp_info.bmiHeader
        .biSize = LenB(bmp_info.bmiHeader)
        .biWidth = Screen.Width / Screen.TwipsPerPixelX
        .biHeight = Screen.Height / Screen.TwipsPerPixelY
        .biPlanes = 1
        .biBitCount = 32
        .biCompression = BI_RGB
        .biSizeImage = .biHeight * (((.biWidth * .biBitCount + 31) And &HFFFFFFE0) \ 8)
    End With

授人于鱼,不如授人于渔
早已停用QQ了
2013-04-16 16:07
compdnycdke
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-10-14
收藏
得分:0 
回复 2楼 风吹过b
次奥  我去试试  谢谢高手指点
2013-04-16 16:28
me4405801
Rank: 2
等 级:论坛游民
帖 子:37
专家分:17
注 册:2006-8-31
收藏
得分:7 
在所有循环体中加DOEVENTS
2013-04-16 17:00
compdnycdke
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-10-14
收藏
得分:0 
以上2个方法都尝试了 还是不得行
2013-04-16 19:54
快速回复:求大神帮我提下速度
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024111 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved