Sign in to follow this  
Followers 0
leetone

Need help with ControlClick

5 posts in this topic

#1 ·  Posted (edited)

I'm trying to make an autoit for a game Warcraft 3. The problem is as I search the forum is that it wouldn't work without controlid. But with the autoitinfo you can't find a controlid, it is blank. Below is my current script:

While 1=1
$hWin = WinGetHandle("[CLASS:Warcraft III; TITLE:Warcraft III]")
ControlClick($hWin, "", "", "Left", 1, 971, 173)
ControlClick($hWin, "", "", "Left", 1, 162, 132)
ControlClick($hWin, "", "", "Left", 1, 123, 234)
ControlClick($hWin, "", "", "Left", 1, 815, 156)
Wend

So far it does send the clicks, but it doesn't do it at the position I set it as. Also the game is in windowed mode.

Thanks in advance!

Edited by leetone

Share this post


Link to post
Share on other sites



Did you use Opt("MouseCoordMode", 0) ?

It may be that the coords you have are the window coords... not the coord for the W3 client.

Share this post


Link to post
Share on other sites

So how do I find the W3 Client code? I'm a newbie I don't understand what is Opt("MouseCoordMode", 0).

Share this post


Link to post
Share on other sites

Wc3 Client coords?

Share this post


Link to post
Share on other sites

Have a look in the help file for MouseCoordMode.

I think client coords are more reliable.

To get the some info, give this a go

AutoItSetOption("MouseCoordMode", 2)
AdlibEnable("_Mouse_Control_GetInfoAdlib", 10)

While 1
    Sleep(0xFFFFFFF)
WEnd
Func _Mouse_Control_GetInfoAdlib()
    Local $a_info = _Mouse_Control_GetInfo()
    If @error Then Return
    ToolTip("Handle = " & $a_info[0] & @CRLF & _
        "Class = " & $a_info[1] & @CRLF & _
        "Mouse X Pos = " & $a_info[2] & @CRLF & _
        "Mouse Y Pos = " & $a_info[3])
EndFunc

Func _Mouse_Control_GetInfo()
    local $client_mpos = MouseGetPos() ; gets client coords because of "MouseCoordMode" = 2
    Local $a_mpos = _ClientToScreen($appHandle, $client_mpos[0], $client_mpos[1]) ; $a_mpos now screen coords   
    If @error Then Return SetError(1, 0, 0)
    Local $a_wfp = DllCall("user32.dll", "hwnd", "WindowFromPoint", "long", $a_mpos[0], "long", $a_mpos[1])
    If @error Then Return SetError(2, 0, 0)
    Local $t_class = DllStructCreate("char[260]")
    DllCall("User32.dll", "int", "GetClassName", "hwnd", $a_wfp[0], "ptr", DllStructGetPtr($t_class), "int", 260)
    Local $a_ret[4] = [$a_wfp[0], DllStructGetData($t_class, 1), $a_mpos[0], $a_mpos[1]]
    Return $a_ret
EndFunc
; ===============================================================================
;~ Translates client coordinates into screen coordinates, [0] = x and [1] = y from the return array.
;~ Requires - AutoItSetOption("MouseCoordMode", 2)
;~ Params
;~   $h_wnd - Identifies the window whose client area is used for the conversion.
;~   $i_x - x pos of the client coord
;~   $i_y - Y pos of the client coord
;~ Returns -
; ===============================================================================
Func _ClientToScreen($h_wnd, $i_x, $i_y)
    ConsoleWrite("here, " & $i_x & "," & $i_y & @CRLF)
    Local $t_point = DllStructCreate("int;int")
   
    DllStructSetData($t_point, 1, $i_x)
    DllStructSetData($t_point, 2, $i_y)
    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $h_wnd, "ptr", DllStructGetPtr($t_point))
   
    Local $a_ret[2] = [DllStructGetData($t_point, 1), DllStructGetData($t_point, 2)]
    ConsoleWrite("here, " & $a_ret[0] & "," & $a_ret[1] & @CRLF)
    Return $a_ret
EndFunc

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0