zxk123 发表于 2012-8-6 16:07:49

怎样的代码可以实现高频率的自动按键

我试过用PostMessage_UDF.au3速度还是不理想
有没有可以实现1秒输出100个到2000个字符以上的代码?

zxk123 发表于 2012-8-6 16:17:24

我知道了,PostMessage_UDF.au3里面加了sleep,影响了速度,这个停顿太不实用了.

32714107 发表于 2012-8-7 09:08:03

楼主自问自答,为什么不能把源码贴出来让大家学习一下?!

qq309266378 发表于 2012-8-8 12:13:48

多深的水池装多少水啊楼主。

zxk123 发表于 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))
                                ;Sleep(1) \\这里会影响效率所以我不要了
                                DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x101, "int", Asc(StringMid($keys, $i, 1)), "long", _MakeLong(1, $ret) + 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

Qokelate 发表于 2012-8-8 14:38:18

Sleep 1是减少CPU占用用的,删掉未必会提升效率

zxk123 发表于 2012-8-8 16:19:02

假设想要停1秒或者更精细那sleep(1000)就做不到,真正的会比这个时间多
页: [1]
查看完整版本: 怎样的代码可以实现高频率的自动按键