找回密码
 加入
搜索
查看: 2865|回复: 6

[效率算法] 怎样的代码可以实现高频率的自动按键

  [复制链接]
发表于 2012-8-6 16:07:49 | 显示全部楼层 |阅读模式
我试过用PostMessage_UDF.au3速度还是不理想
有没有可以实现1秒输出100个到2000个字符以上的代码?
 楼主| 发表于 2012-8-6 16:17:24 | 显示全部楼层
我知道了,PostMessage_UDF.au3里面加了sleep,影响了速度,这个停顿太不实用了.
发表于 2012-8-7 09:08:03 | 显示全部楼层
楼主自问自答,为什么不能把源码贴出来让大家学习一下?!
发表于 2012-8-8 12:13:48 | 显示全部楼层
多深的水池装多少水啊楼主。
 楼主| 发表于 2012-8-8 13:46:58 | 显示全部楼层
PostMessage_UDF.au3里面是用sleep(1)延缓的,我就想论坛之前有人发过_HighPrecisionSleep高精度延迟,换了效果还是不理想,所以干脆删掉了延迟。
Func _SendKeys($hWnd, $keys)
        If $hWnd <= 0 Or StringLen($keys) = 0 Then  ;StringLen字符长度
                SetError(-1)
                Return False
        EndIf

        $keys = StringUpper($keys)

        $keys = StringReplace($keys, "`", Chr(0xC0))
        $keys = StringReplace($keys, "~", Chr(0xC0))
        $keys = StringReplace($keys, "-", Chr(0xBD))
        $keys = StringReplace($keys, "=", Chr(0xBB))
        $keys = StringReplace($keys, "{BACKSPACE}", Chr(0x8))
        $keys = StringReplace($keys, "{TAB}", Chr(0x9))
        $keys = StringReplace($keys, "{ENTER}", Chr(0xD))
    $keys = StringReplace($keys, "{ALT}", Chr(0x12))
        $keys = StringReplace($keys, "{CTRL}", Chr(0x9))

        $keys = StringReplace($keys, "{ESC}", Chr(0x1B))
        $keys = StringReplace($keys, "{F1}", Chr(0x70))
        $keys = StringReplace($keys, "{F2}", Chr(0x71))
        $keys = StringReplace($keys, "{F3}", Chr(0x72))
        $keys = StringReplace($keys, "{F4}", Chr(0x73))
        $keys = StringReplace($keys, "{F5}", Chr(0x74))
        $keys = StringReplace($keys, "{F6}", Chr(0x75))
        $keys = StringReplace($keys, "{F7}", Chr(0x76))
        $keys = StringReplace($keys, "{F8}", Chr(0x77))
        $keys = StringReplace($keys, "{F9}", Chr(0x78))
        $keys = StringReplace($keys, "{F10}", Chr(0x79))
        $keys = StringReplace($keys, "{F12}", Chr(0x7B))
        $keys = StringReplace($keys, "{SHIFT}", "+")

    Local $i, $ret
        Local $shiftdown = False
        Local $user32 = DllOpen("user32.dll")

        For $i = 1 To StringLen($keys)
                If StringMid($keys, $i, 1) = "+" Then
                        DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x100, "int", 0x10, "long", 0x002A0001)
                        DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x100, "int", 0x10, "long", 0x402A0001)
                        $shiftdown = True
                        ;Sleep(1) \\这里会影响效率所以我不要了
                        ContinueLoop
                Else
                        $ret = DllCall($user32, "int", "MapVirtualKey", "int", Asc(StringMid($keys, $i, 1)), "int", 0)
                        If IsArray($ret) Then
                                DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x100, "int", Asc(StringMid($keys, $i, 1)), "long", _MakeLong(1, $ret[0]))
                                ;Sleep(1) \\这里会影响效率所以我不要了
                                DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x101, "int", Asc(StringMid($keys, $i, 1)), "long", _MakeLong(1, $ret[0]) + 0xC0000000)
                                ;Sleep(1) \\这里会影响效率所以我不要了
                        EndIf
                EndIf
                If $shiftdown Then
                        DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x101, "int", 0x10, "long", 0xC02A0001)
                        ;Sleep(1) \\这里会影响效率所以我不要了
                        $shiftdown = False
                EndIf
        Next

        If $user32 <> -1 Then DllClose($user32)

        Return True
EndFunc
发表于 2012-8-8 14:38:18 | 显示全部楼层
Sleep 1  是减少CPU占用用的,删掉未必会提升效率
 楼主| 发表于 2012-8-8 16:19:02 | 显示全部楼层
假设想要停1秒或者更精细那sleep(1000)就做不到,真正的会比这个时间多
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-15 00:48 , Processed in 0.097173 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表