Jump to content

Need help with ControlClick


leetone
 Share

Recommended Posts

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
Link to comment
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]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...