zxk123 发表于 2014-6-9 06:59:35

如何使用PostMessage_UDF去按住某一个键?

已经知道用_senkeys去发送按键。
那如果我需要实现按住某个按键,应该使用哪个函数或,还是要怎么修改PostMessage_UDF.au3里面的函数才能实现?
求大神指点~
Func _SendKeys($hWnd, $keys)
        If $hWnd <= 0 Or StringLen($keys) = 0 Then
                SetError(-1)
                Return False
        EndIf
       
        $keys = StringUpper($keys)
       
        $keys = StringReplace($keys, "None", Chr(0x00))
        $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, "{ENTER}", Chr(0xD))
        $keys = StringReplace($keys, "{TAB}", Chr(0x9))
        $keys = StringReplace($keys, "{ESC}", Chr(0x1B))
        $keys = StringReplace($keys, "{SPACE}", Chr(0x20))
        $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, "F11", Chr(0x7A))
        $keys = StringReplace($keys, "F12", Chr(0x7B))
        $keys = StringReplace($keys, "Num 0", Chr(0x60))
        $keys = StringReplace($keys, "Num 1", Chr(0x61))
        $keys = StringReplace($keys, "Num 2", Chr(0x62))
        $keys = StringReplace($keys, "Num 3", Chr(0x63))
        $keys = StringReplace($keys, "Num 4", Chr(0x64))
        $keys = StringReplace($keys, "Num 5", Chr(0x65))
        $keys = StringReplace($keys, "Num 6", Chr(0x66))
        $keys = StringReplace($keys, "Num 7", Chr(0x67))
        $keys = StringReplace($keys, "Num 8", Chr(0x68))
        $keys = StringReplace($keys, "Num 9", Chr(0x69))
        $keys = StringReplace($keys, "Left", Chr(0x25))
        $keys = StringReplace($keys, "Up", Chr(0x26))
        $keys = StringReplace($keys, "Right", Chr(0x27))
        $keys = StringReplace($keys, "Down", Chr(0x28))
        $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   ;==>_SendKeys
页: [1]
查看完整版本: 如何使用PostMessage_UDF去按住某一个键?