Sign in to follow this  
Followers 0
CWW256

Mouse click location learning script

4 posts in this topic

#1 ·  Posted (edited)

This is part of a script that will learn to click places that you specify in a "learning mode" that can be used in another script.

I have been casually using AutoIt for about a year now, and everything I have learned (which is not a whole lot) has been from this forum and the help files. I have no prievious backround in any kind of programming language, so I am asking for advice on ways to make this better, more efficient and possibly incorporate it in a GUI. Also, my biggest concern is making it more dynamically expandable in terms of points learned. As you may see, right now it only learns 6 points, so any advice on how to efficiently add the ability to have more points learned would be great.

Global $area1[2]
Global $area2[2]
Global $area3[2]
Global $area4[2]
Global $area5[2]
Global $area6[2]
Global $area7[2]
Global $area8[2]
Global $area9[2]
Global $area10[2]
Global $area11[2]
Global $area12[2]
Global $PointTemp[2]
Global $RunLearning
Global $Learned
Global $ExitLearning
HotKeySet("{F5}", "StartLearning")
HotKeySet("{F7}", "StoreCurrentPoint")
HotKeySet("{F9}", "WriteLearnedIni")
HotKeySet("{F11}", "PlayLearned")
HotKeySet("{F10}", "ExitLearning")

$RunLearning = MsgBox(4,"Learning", "Change/view learned coordinates?")
If $RunLearning = 6 Then
    Call("LearnCoordinates")
Else
    MsgBox(0,"","Reading coordinates from INI.")
    Call("ReadLearned")
EndIf

Func LearnCoordinates()
    While 1
        Sleep(100)
        If FileExists("learnedcoordinates.ini") = 0 Then
            ToolTip("No Coordinate INI found. Press F5 to start learning, or press F9 to create INI.")
        ElseIf FileExists("learnedcoordinates.ini") = 1 and $Learned = 0 Then
            ToolTip("Coordinate INI found. Press F5 to set new points and press F11 to show learned coordinates.")
        Else
            ToolTip("Coordinates learned, press F9 to write INI, F11 to show learned, and press F10 to end learning.")
        EndIf
        If $ExitLearning = 1 Then
            ToolTip("Exiting learning mode.")
            ExitLoop
        EndIf
    WEnd
EndFunc

Func StartLearning()
    While 1
        Sleep(100)
        If $area1[0] = 0 Then
            ToolTip("Point at area1 and press F7 to save.")
        ElseIf $area2[0] = 0 Then
            ToolTip("Point at area2 and press F7 to save.")
        ElseIf $area3[0] = 0 Then
            ToolTip("Point at area3 and press F7 to save.")
        ElseIf $area4[0] = 0 Then
            ToolTip("Point at area4 and press F7 to save.")
        ElseIf $area5[0] = 0 Then
            ToolTip("Point at area5 and press F7 to save.")
        ElseIf $area6[0] = 0 Then
            ToolTip("Point at area6 and press F7 to save.")
        ElseIf $area1[0] <> 0 And $area5[0] <> 0 And $area6[0] <> 0 and $area3[0] <> 0 and $area2[0] <> 0 and $area4[0] <> 0 Then
            ExitLoop
        EndIf
        If $PointTemp[0] <> 0 and $area1[0] = 0 Then
            $area1[0] = $PointTemp[0]
            $area1[1] = $PointTemp[1]
            $PointTemp[0] = 0
            $PointTemp[1] = 0
        EndIf
        If $PointTemp[0] <> 0 and $area1[0] <> 0 and $area2[0] = 0 Then
            $area2[0] = $PointTemp[0]
            $area2[1] = $PointTemp[1]
            $PointTemp[0] = 0
            $PointTemp[1] = 0
        EndIf
        If $PointTemp[0] <> 0 and $area1[0] <> 0 and $area2[0] <> 0 and $area3[0] = 0 Then
            $area3[0] = $PointTemp[0]
            $area3[1] = $PointTemp[1]
            $PointTemp[0] = 0
            $PointTemp[1] = 0
        EndIf
        If $PointTemp[0] <> 0 and $area1[0] <> 0 and $area2[0] <> 0 and $area3[0] <> 0 and $area4[0] = 0 Then
            $area4[0] = $PointTemp[0]
            $area4[1] = $PointTemp[1]
            $PointTemp[0] = 0
            $PointTemp[1] = 0
        EndIf
        If $PointTemp[0] <> 0 and $area1[0] <> 0 and $area2[0] <> 0 and $area3[0] <> 0 and $area4[0] <> 0 and $area5[0] = 0 Then
            $area5[0] = $PointTemp[0]
            $area5[1] = $PointTemp[1]
            $PointTemp[0] = 0
            $PointTemp[1] = 0
        EndIf
        If $PointTemp[0] <> 0 and $area1[0] <> 0 and $area2[0] <> 0 and $area3[0] <> 0 and $area4[0] <> 0 and $area5[0] <> 0 and $area6[0] = 0 Then
            $area6[0] = $PointTemp[0]
            $area6[1] = $PointTemp[1]
            $PointTemp[0] = 0
            $PointTemp[1] = 0
        EndIf
        $Learned = 1
    WEnd

EndFunc

Func StoreCurrentPoint()
    $PointTemp = MouseGetPos()
EndFunc

Func WriteLearnedIni()
    Sleep(100)
    IniWrite("learnedcoordinates.ini", "Coordinates","area1x",$area1[0])
    IniWrite("learnedcoordinates.ini", "Coordinates","area1y",$area1[1])
    IniWrite("learnedcoordinates.ini", "Coordinates","area2x",$area2[0])
    IniWrite("learnedcoordinates.ini", "Coordinates","area2y",$area2[1])
    IniWrite("learnedcoordinates.ini", "Coordinates","area3x",$area3[0])
    IniWrite("learnedcoordinates.ini", "Coordinates","area3y",$area3[1])
    IniWrite("learnedcoordinates.ini", "Coordinates","area4x",$area4[0])
    IniWrite("learnedcoordinates.ini", "Coordinates","area4y",$area4[1])
    IniWrite("learnedcoordinates.ini", "Coordinates","area5x",$area5[0])
    IniWrite("learnedcoordinates.ini", "Coordinates","area5y",$area5[1])
    IniWrite("learnedcoordinates.ini", "Coordinates","area6x",$area6[0])
    IniWrite("learnedcoordinates.ini", "Coordinates","area6y",$area6[1])
EndFunc

Func ReadLearned()
    Sleep(100)
    $area7[0] = IniRead("learnedcoordinates.ini", "Coordinates","area1x",0)
    $area7[1] = IniRead("learnedcoordinates.ini", "Coordinates","area1y",0)
    $area8[0] = IniRead("learnedcoordinates.ini", "Coordinates","area2x",0)
    $area8[1] = IniRead("learnedcoordinates.ini", "Coordinates","area2y",0)
    $area9[0] = IniRead("learnedcoordinates.ini", "Coordinates","area3x",0)
    $area9[1] = IniRead("learnedcoordinates.ini", "Coordinates","area3y",0)
    $area10[0] = IniRead("learnedcoordinates.ini", "Coordinates","area4x",0)
    $area10[1] = IniRead("learnedcoordinates.ini", "Coordinates","area4y",0)
    $area11[0] = IniRead("learnedcoordinates.ini", "Coordinates","area5x",0)
    $area11[1] = IniRead("learnedcoordinates.ini", "Coordinates","area5y",0)
    $area12[0] = IniRead("learnedcoordinates.ini", "Coordinates","area6x",0)
    $area12[1] = IniRead("learnedcoordinates.ini", "Coordinates","area6y",0)
EndFunc

Func PlayLearned()
    Sleep(100)
    $area7[0] = IniRead("learnedcoordinates.ini", "Coordinates","area1x",0)
    $area7[1] = IniRead("learnedcoordinates.ini", "Coordinates","area1y",0)
    $area8[0] = IniRead("learnedcoordinates.ini", "Coordinates","area2x",0)
    $area8[1] = IniRead("learnedcoordinates.ini", "Coordinates","area2y",0)
    $area9[0] = IniRead("learnedcoordinates.ini", "Coordinates","area3x",0)
    $area9[1] = IniRead("learnedcoordinates.ini", "Coordinates","area3y",0)
    $area10[0] = IniRead("learnedcoordinates.ini", "Coordinates","area4x",0)
    $area10[1] = IniRead("learnedcoordinates.ini", "Coordinates","area4y",0)
    $area11[0] = IniRead("learnedcoordinates.ini", "Coordinates","area5x",0)
    $area11[1] = IniRead("learnedcoordinates.ini", "Coordinates","area5y",0)
    $area12[0] = IniRead("learnedcoordinates.ini", "Coordinates","area6x",0)
    $area12[1] = IniRead("learnedcoordinates.ini", "Coordinates","area6y",0)
    MouseMove($area7[0], $area7[1])
    MouseMove($area8[0], $area8[1])
    MouseMove($area9[0], $area9[1])
    MouseMove($area10[0], $area10[1])
    MouseMove($area11[0], $area11[1])
    MouseMove($area12[0], $area12[1])
EndFunc

Func ExitLearning()
    $ExitLearning = 1
EndFunc

Func ColorGrabber()
    Local $C[3]
    Sleep(100)
    $C[0] = InputBox("", "Input x coordinate.")
    $C[1] = InputBox("", "Input y coordinate.")
    $C[2] = PixelGetColor($C[0], $C[1])
    Return($C[2])
EndFunc

The "CODE" option on the forums is stripping out all the nice whitespace, so here is a copy of the script itsself.

Thanks for any advice.

Edited by CWW256

Share this post


Link to post
Share on other sites



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