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