已解决:对不激活的窗口利用句柄发送键盘消息
本帖最后由 sysbin 于 2009-5-23 13:05 编辑能不能根据检测到的没激活的窗口的句柄发送键盘点击,也就是说在后台完成鼠标动作或键盘动作,希望得到高手指点一二。 本帖最后由 mnm001 于 2009-5-18 14:13 编辑
可以。 开多线程Func Process3()
while 1
AdlibEnable("clickwindow")
sleep(3000)
WEnd
EndFunc
Func clickwindow()
If WinExists("Windows Internet Explorer") Then
ControlClick ("Windows Internet Explorer","","Button1")
EndIf
EndFunc我这个是点击JS 的。 前两天也想了很多办法。只有这个能用。希望能对你有帮助。 基本上你说的是游戏吧 在ControlClick有效的情况下就用ControlClick
无效的情况下 就用postmessage 这个小问题曾经困扰了很多人,用POSTMESSAGE即可解决,这类应用一般用于游戏中控制,有一个函数Postmessage_UDF,里面包含了后台鼠标和键盘发送消息的方法,在用postmessage_udf时一个特别重要的问题是你要操作对象的句柄(Handle),对于有些游戏,特别是网页类的游戏,GUI的句柄和CONTROL的句柄是不一样的,你要确定出你要操作对象的句柄,可以用Auto Window Info来查看。附上一个小例子:
#include <PostMessage_UDF.au3>
$Hwnd = WinGetHandle("计算器")
_MouseClick($hWnd, "left", 19, 12)
_SendText($Hwnd,"9")
这个程序是打开WINDOWS系统的计算器,后台发送9。 谢谢楼上的回答 PostMessage_UDF.au3
哪里可以找到这个呀?我是小白。 回复 4# scott2000
我怎么找不到有Postmessage这个函数?? ;--PostMessage User Defined Functions--
;--Written by Shynd for use with DA--
#include-once
Func _MakeLong($LoWord, $HiWord)
Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc
Func _MouseClick($hWnd, $button, $x, $y, $times=1, $delay=250)
If $hWnd = 0 Then
SetError(-1)
Return
EndIf
Local $ix
Local $lParam = _MakeLong($x, $y)
Local $user32 = DllOpen("user32.dll")
$button = StringLower($button)
If $button = "left" Then
For $ix = 1 To $times
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x200, "int", 0, "long", $lParam)
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x201, "int", 1, "long", $lParam)
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x202, "int", 0, "long", $lParam)
If $ix$times Then Sleep($delay)
Next
ElseIf $button = "right" Then
For $ix = 1 To $times
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x200, "int", 0, "long", $lParam)
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x204, "int", 2, "long", $lParam)
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x205, "int", 0, "long", $lParam)
If $ix$times Then Sleep($delay)
Next
Else
SetError(-2)
If $user32 <> -1 Then DllClose($user32)
Return
EndIf
If $user32 <> -1 Then DllClose($user32)
EndFunc
Func _MouseUseSpell($hWnd, $x, $y, $selfcast=False, $sx=310, $sy=163)
Local $user32 = DllOpen("user32.dll")
;Click the spell panel
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x200, "int", 0, "long", _MakeLong(547, 400))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x201, "int", 0, "long", _MakeLong(547, 400))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x202, "int", 0, "long", _MakeLong(547, 400))
;Double-click the spell
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x200, "int", 0, "long", _MakeLong($x, $y))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x201, "int", 0, "long", _MakeLong($x, $y))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x202, "int", 0, "long", _MakeLong($x, $y))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x201, "int", 0, "long", _MakeLong($x, $y))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x202, "int", 0, "long", _MakeLong($x, $y))
;If selfcast, click on character
If $selfcast Then
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x200, "int", 0, "long", _MakeLong($sx, $sy))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x201, "int", 0, "long", _MakeLong($sx, $sy))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x202, "int", 0, "long", _MakeLong($sx, $sy))
EndIf
If $user32 <> -1 Then DllClose($user32)
EndFunc
Func _MouseUseSkill($hWnd, $x, $y)
Local $user32 = DllOpen("user32.dll")
;Click the skill panel
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x200, "int", 0, "long", _MakeLong(547, 370))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x201, "int", 0, "long", _MakeLong(547, 370))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x202, "int", 0, "long", _MakeLong(547, 370))
;Double-click the skill
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x200, "int", 0, "long", _MakeLong($x, $y))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x201, "int", 0, "long", _MakeLong($x, $y))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x202, "int", 0, "long", _MakeLong($x, $y))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x201, "int", 0, "long", _MakeLong($x, $y))
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x202, "int", 0, "long", _MakeLong($x, $y))
If $user32 <> -1 Then DllClose($user32)
EndFunc
Func _SendKeys($hWnd, $keys)
If $hWnd = 0 Or StringLen($keys) = 0 Then
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, "{ENTER}", Chr(0xD))
$keys = StringReplace($keys, "{TAB}", 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, "{F11}", Chr(0x7A))
$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
Func _SendText($hWnd, $str)
If $hWnd = 0 Or StringLen($str) = 0 Then
SetError(-1)
Return
EndIf
Local $user32 = DllOpen("user32.dll")
For $i = 1 To StringLen($str)
DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x102, "int", Asc(StringMid($str, $i, 1)), "long", 0)
Sleep(1)
Next
If $user32 <> -1 Then DllClose($user32)
EndFunc
Func _SendChatMessage($hWnd, $str)
If $hWnd = 0 Or StringLen($str) = 0 Then
SetError(-1)
Return
EndIf
_SendKeys($hWnd, "{ENTER}")
Sleep(50)
_SendText($hWNd, $str)
Sleep(30)
_SendKeys($hWNd, "{ENTER}")
EndFunc
Func _SendWhisper($hWnd, $name, $str)
If $hWnd = 0 Or StringLen($str) = 0 Or StringLen($name) = 0 Then
SetError(-1)
Return
EndIf
_SendKeys($hWnd, "{ESC}+" & Chr(0xDE))
Sleep(50)
_SendText($hWnd, $name)
Sleep(1)
_SendKeys($hWNd, "{ENTER}")
Sleep(30)
_SendText($hWnd, $str)
Sleep(30)
_SendKeys($hWnd, "{ENTER}")
EndFunc
Func _ArrowKey($hWnd, $key)
If $hWnd = 0 Or ( $key <> "left" And $key <> "right" And $key <> "up" And $key <> "down" ) Then
SetError(-1)
Return
EndIf
Local $wParam, $lParam, $ret
If $key = "left" Then
$wParam = 0x25
$lParam = 0x14B0001
ElseIf $key = "right" Then
$wParam = 0x27
$lParam = 0x14D0001
ElseIf $key = "down" Then
$wParam = 0x28
$lParam = 0x1500001
ElseIf $key = "up" Then
$wParam = 0x26
$lParam = 0x1480001
EndIf
Local $user32 = DllOpen("user32.dll")
$ret = DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x100, "int", $wParam, "int", $lParam)
If $ret = 0 Then
SetError(-2)
If $user32 <> -1 Then DllClose($user32)
Return
EndIf
Sleep(2)
$ret = DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x101, "int", $wParam, "int", ($lParam + 0xC0000000))
If $ret = 0 Then
SetError(-3)
If $user32 <> -1 Then DllClose($user32)
Return
EndIf
If $user32 <> -1 Then DllClose($user32)
EndFunc
Func _PostMessage($hWnd, $msgID, $wParam, $lParam)
Local $ret = DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", $msgID, "int", $wParam, "int", $lParam)
If IsArray($ret) Then
Return $ret
Else
SetError(-1)
Return False
EndIf
EndFunc 学习了 楼上的 PostMessage_UDF.au3"(28,40) : error: 表达式错误
If $ix$times Then PostMessage_UDF.au3"(36,40) : error: 表达式错误
If $ix$times Then
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
页:
[1]