Jump to content
liluom

ControlClick did not click properly

Recommended Posts

liluom

Hi everyone! I want to click a button by ControlClick(), but it wont click until I move around my mouse cursor. Do it have not enough privilege? My computer use Windows 7 (32bit), I have just test in some different computers (Windows 7 too) and it can click so smoothly. I dont know why? Please help me.

Share this post


Link to post
Share on other sites
liluom
Func _imgsearchhidden($imagetofind, $itolerance = 0, $ileft = 0, $itop = 0, $iright = -1, $ibottom = -1)
    Local $result[1], $hhbitmapimagetofind, $hbitmapfind, $speed
    $speed = TimerInit()
    If $iright = -1 Then $iright = $hwidth
    If $ibottom = -1 Then $ibottom = $hheight
    $image = StringSplit($imagetofind, "|")
    For $i = 0 To $image[0]
        If FileExists($path & $image[$i]) = 0 Then ContinueLoop
        $hbitmapfind = _gdiplus_bitmapcreatefromfile($path & $image[$i])
        $hhbitmapimagetofind = _gdiplus_bitmapcreatehbitmapfrombitmap($hbitmapfind)
        $result = DllCall($dll, "str", "ImageSearchExt", "int", $ileft, "int", $itop, "int", $iright, "int", $ibottom, "int", $itolerance, "ptr", $hhbitmapimagetofind, "ptr", $hbmp)
        _winapi_deleteobject($hhbitmapimagetofind)
        _gdiplus_bitmapdispose($hbitmapfind)
        If NOT IsArray($result) Then
            Local $a[1]
            ConsoleWrite("Not an array " & $path & $image[$i] & @CR)
            Return $a
        ElseIf $result[0] <> 0 Then
            FileWriteLine("ImgSearchLog.log", _nowtime(5) & " - FOUND " & $path & $image[$i] & " - SPEED: " & Round(TimerDiff($speed)) & "ms")
            ExitLoop
        EndIf
        If TimerDiff($speed) >= 250 Then
            ConsoleWrite("-- " & _nowtime(5) & " - WARNING: " & $path & $image[$i] & " - SPEED: " & Round(TimerDiff($speed)) & "ms TOO SLOW" & @CR)
            FileWriteLine("ImgSearchLog.log", _nowtime(5) & " - WARNING: " & $path & $image[$i] & " - SPEED: " & Round(TimerDiff($speed)) & "ms TOO SLOW")
        EndIf
    Next
    Return StringSplit($result[0], "|", $str_nocount)
EndFunc

Func clickimg($img, $tolerance = 50, $x = "", $y = "", $mode = 0, $xstart = 0, $ystart = 0, $xend = -1, $yend = -1)
    Local $a = _imgsearchhidden($img, $tolerance, $xstart, $ystart, $xend, $yend)
    If $a[0] = 1 Then
        If $x = "" OR $y = "" Then
            ConsoleWrite("Found " & $img & ", Click " & $a[1] & ", " & $a[2] & @CR)
            ControlClick($winhandle, "", "", "", 1, $a[1], $a[2])
        Else
            If $mode = 0 Then
                ConsoleWrite("Found " & $img & ", Click " & $x & ", " & $y & @CR)
                ControlClick($winhandle, "", "", "", 1, $x, $y)
            Else
                $x = $a[1] + $x
                $y = $a[2] + $y
                ConsoleWrite("Found " & $img & ", Click " & $x & ", " & $y & @CR)
                ControlClick($winhandle, "", "", "", 1, $x, $y)
            EndIf
        EndIf
        Return True
    EndIf
    Return False
EndFunc

It could find image, but could not click at images until i move my cursor. Unless I move my mouse, it won't click. If I always move, it will click so smoothly.

Thank for your time! Sorry for my bad english!

Share this post


Link to post
Share on other sites
Jos
4 hours ago, liluom said:

Thank for your time! Sorry for my bad english!

Understood but you haven't answered my 2 simple questions. The posted script is not a reproducer and doesn't do anything hen ran.

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
jdelaney

You can look into mousemove prior to the click.   Or just use mouseclick.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

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

×