Sign in to follow this  
Followers 0
PhoTTo

Help Making a AutoIT SCRIPT

21 posts in this topic

Hello, i`m new with AutoIT i just want help in making a script. It`s a very simple script when i thinking but i can`t put it at work because of lack of experience.

In want a script with a GUI interface looking like in attach pic. The purpose of the script is:

- when i push the first start(SECONDARY) button i want to memorize the left click mouse button postion and put it on the right part of the screen (the left click mouse should not actually be push in window just to memorize)until i push Stop button or use Hotkeys.

- same with the second start(PRIMARY) button but just one Left Click mouse position to memorize

- the third Start button will actually start the order of the clicks in this order: one position from the SECONDARY list with the PRIMARY position and so on until the list with position from SECONDARY is over.

- the mouse movement set to very fast

EX:

MouseMove(391,371,0) SECONDARY LIST pos1

MouseDown("left")

MouseUp("left")

MouseMove(353,302,0)MASTER

MouseDown("left")

MouseUp("left")

MouseMove(351,368,0) SECONDARY LIST pos2

MouseDown("left")

MouseUp("left")

MouseMove(353,302,0)MASTER

MouseDown("left")

MouseUp("left")

MouseMove(319,371,0)SECONDARY LIST pos3

MouseDown("left")

MouseUp("left")

MouseMove(353,302,0) MASTER

MouseDown("left")

MouseUp("left")

......

Thanks and please help me with these script

post-55168-12625930783205_thumb.jpg

Share this post


Link to post
Share on other sites



In want a script with a GUI interface looking like in attach pic. The purpose of the script is:

Download SciTe4AutoIt3 and use Koda to design your forms. It's very simple to use and it will generate the code to make it for you.

- when i push the first start(SECONDARY) button i want to memorize the left click mouse button postion and put it on the right part of the screen (the left click mouse should not actually be push in window just to memorize)until i push Stop button or use Hotkeys.

You need variables and nice if statement on the go, something like this perhaps?

#include <Misc.au3>

Dim $clickX, $clickY

While 1
    Sleep(50)
    If _IsPressed("01") Then ; "01" refers to Left click
        $clickX = MouseGetPos(0)
        $clickY = MouseGetPos(1)
        ConsoleWrite("-> Resulting co-ordinates: " & $clickX & ", " & $clickY & @CRLF)
        Exit
    EndIf
WEnd

This will put the X and Y co-ordinates of the mouse click in a variable then print the output to the console. You can do whatever you need with it.

- same with the second start(PRIMARY) button but just one Left Click mouse position to memorize

Just use the code above, it's the same principle.

- the third Start button will actually start the order of the clicks in this order: one position from the SECONDARY list with the PRIMARY position and so on until the list with position from SECONDARY is over.

Ok now I think I'm understanding what you want. You want to store the location of mouse clicks then play them back? There is already something for you to do that with "AU3Recorder" Posted Image

- the mouse movement set to very fast

Then use the Sleep() function.

Share this post


Link to post
Share on other sites

This is how i wanted to look the problem is i don`t know how write IT

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
Opt("MouseClickDelay",0)
Opt("MouseClickDownDelay",0)
Opt("MouseClickDragDelay",0)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

#Region ### START Form ### F
$Form1 = GUICreate("Form1", 494, 454, 205, 116)
$Button1 = GUICtrlCreateButton("Start POS", 16, 22, 81, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Stop POS", 112, 22, 81, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Start Destination", 22, 293, 89, 25, $WS_GROUP)
$Button4 = GUICtrlCreateButton("Stop Destination", 120, 293, 89, 25, $WS_GROUP)
$Button5 = GUICtrlCreateButton("START STACKING", 187, 371, 137, 49, $WS_GROUP)
$List1 = GUICtrlCreateList("", 232, 22, 249, 253)
$List2 = GUICtrlCreateList("", 232, 293, 249, 32)
GUISetState(@SW_SHOW)
#EndRegion ### END Form ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

;POSITION LIST
Dim $clickX, $clickY

While 1
    Sleep(50)
    If _IsPressed("01") Then ; "01" refers to Left click
        $clickX = MouseGetPos(0)
        $clickY = MouseGetPos(1)
        ConsoleWrite("-> Resulting co-ordinates: " & $clickX & ", " & $clickY & @CRLF)
        Exit
    EndIf
WEnd

;DESTINATION LIST
Dim $clickX, $clickY

While 1
    Sleep(50)
    If _IsPressed("01") Then ; "01" refers to Left click
        $clickX = MouseGetPos(0)
        $clickY = MouseGetPos(1)
        ConsoleWrite("-> Resulting co-ordinates: " & $clickX & ", " & $clickY & @CRLF)
        Exit
    EndIf
WEnd

;RUN STACKING

; MouseMove(391,371,0)FIRST click from POSITON LIST
;MouseDown("left")
;MouseUp("left")
;MouseMove(353,302,0) click from DESTINATION LIST
;MouseDown("left")
;MouseUp("left")
;MouseMove(351,368,0)SECOND click from POSITON LIST
;MouseDown("left")
;MouseUp("left")
;MouseMove(353,302,0)click from DESTINATION LIST
;MouseDown("left")
;MouseUp("left")
;MouseMove(319,371,0)THIRD click from POSTION LIST
;MouseDown("left")
;MouseUp("left")
;MouseMove(353,302,0) click from DESTINATION LIST
;MouseDown("left")
;MouseUp("left")
; and so on until POSITION LIST IT`s OVER

Share this post


Link to post
Share on other sites

Wow Posted Image where to begin...

Just copying and pasting code will not always work. Firstly, you have two while loops:

;POSITION LIST
Dim $clickX, $clickY

While 1
    Sleep(50)
    If _IsPressed("01") Then ; "01" refers to Left click
        $clickX = MouseGetPos(0)
        $clickY = MouseGetPos(1)
        ConsoleWrite("-> Resulting co-ordinates: " & $clickX & ", " & $clickY & @CRLF)
        Exit
    EndIf
WEnd

;DESTINATION LIST
Dim $clickX, $clickY

While 1
    Sleep(50)
    If _IsPressed("01") Then ; "01" refers to Left click
        $clickX = MouseGetPos(0)
        $clickY = MouseGetPos(1)
        ConsoleWrite("-> Resulting co-ordinates: " & $clickX & ", " & $clickY & @CRLF)
        Exit
    EndIf
WEnd

The second will never occur because the first is infinite.

Secondly, please get into the habit of renaming variables so that they make sense. What is $List1 and $List2 for, X and Y? Name them and it makes our lives easier to understand what you want.

Share this post


Link to post
Share on other sites

i put a picture sample because i can`t explain.

post-55168-12625994791938_thumb.jpg

Share this post


Link to post
Share on other sites

So you want to track the mouse positions?

Yes and after they are memorize play them in that order (red lines) with left click.

Sorry for beeing so not understandable.

Share this post


Link to post
Share on other sites

Script Explanation:

*Click Start POS Button

Action: right click on the 1,2,3,4,... location on the screen

*Click Stop Pos Button

Action: Store location of 1,2,3,4,....

*Start Destination Button

Action: right click on the 5 location on the screen

*Click Stop Destination Button

Action: Store location of the 5

*START STACKING Button

Action: Perform left click in this order with mouse max mouse speed

1,5,2,5,3,5,4,5,....

post-55168-12626821376779_thumb.gif

Share this post


Link to post
Share on other sites

Script Explanation:

*Click Start POS Button

Action: right click on the 1,2,3,4,... location on the screen

*Click Stop Pos Button

Action: Store location of 1,2,3,4,....

Do you know the position of 1, 2, 3, and 4? If not, use PixelSearch to scan the screen for them, if you know the colour.

Share this post


Link to post
Share on other sites

Do you know the position of 1, 2, 3, and 4? If not, use PixelSearch to scan the screen for them, if you know the colour.

The location of the spots (1,2,3,4,5) got to be store(in a list in the right part) when i right click on them.

Share this post


Link to post
Share on other sites

The location of the spots (1,2,3,4,5) got to be store(in a list in the right part) when i right click on them.

Oh I see.

Try this:

#include <Misc.au3>
#include <Array.au3>

Dim $xySpots[4][2]

_MakeSpots()
_ArrayDisplay($xySpots)

Func _MakeSpots()
    Local $clickCount = 0, $xyPos

    While $clickCount < 4
        If _IsPressed("01") Then
            ConsoleWrite("Clicked!" & @CRLF)
            $xyPos = MouseGetPos()
            $xySpots[$clickCount][0] = $xyPos[0]
            $xySpots[$clickCount][1] = $xyPos[1]
            $clickCount += 1
        EndIf
        Sleep(50)
    WEnd
EndFunc

The X/Y positions are stored in the $xySpots array.

Share this post


Link to post
Share on other sites

This is what i do so far, the only thing that remain is how to put STACKING button at work.

*STACKING Button

Action: Perform left click in this order with mouse max mouse speed

1,5,2,5,3,5,4,5,....

it must to take the first position in the list 1 with 5 then 2 with 5 and so on.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Misc.au3>
#include <Array.au3>

$hGUI = GUICreate("Stacker", 494, 454)
$btnStart = GUICtrlCreateButton("Start POS", 16, 22, 81, 25)
$btnStop = GUICtrlCreateButton("Stop POS", 112, 22, 81, 25)
$btnStartDes = GUICtrlCreateButton("Start Destination", 22, 293, 89, 25)
$btnStopDes = GUICtrlCreateButton("Stop Destination", 120, 293, 89, 25)
$btnStartStack = GUICtrlCreateButton("START STACKING", 187, 371, 137, 49)
;$lstXY = GUICtrlCreateList("", 232, 22, 249, 253)
$lstXY = GUICtrlCreateListView("", 232, 22, 249, 253)
_GUICtrlListView_AddColumn($lstXY, "X", 100)
_GUICtrlListView_AddColumn($lstXY, "Y", 100)
$lst2XY = GUICtrlCreateListView("", 232, 293, 249, 50)
_GUICtrlListView_AddColumn($lst2XY, "X", 100)
_GUICtrlListView_AddColumn($lst2XY, "Y", 100)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnStart
            Dim $xySpots[30][2]
            _MakeSpots()
            _GUICtrlListView_AddArray($lstXY, $xySpots)
            AdlibEnable("_MakeSpots")
        Case $btnStop
            AdlibDisable()
            $lstXY = GUICtrlCreateListView("", 232, 22, 249, 253)
            _GUICtrlListView_AddColumn($lstXY, "X", 100)
            _GUICtrlListView_AddColumn($lstXY, "Y", 100)
            GUISetState(@SW_SHOW)
        Case $btnStartDes
             Dim $xyDest[1][2]
             _Destination()
             _GUICtrlListView_AddArray($lst2XY, $xyDest)
             AdlibEnable("_Destination")
        Case $btnStopDes
             AdlibDisable()
             $lst2XY = GUICtrlCreateListView("", 232, 293, 249, 50)
            _GUICtrlListView_AddColumn($lst2XY, "X", 100)
            _GUICtrlListView_AddColumn($lst2XY, "Y", 100)
            GUISetState(@SW_SHOW)
        Case $btnStartStack

    EndSwitch
WEnd






Func _MakeSpots()
    Local $clickCount = 0, $xyPos
    Do
        If _IsPressed("02") Then
                ConsoleWrite("Clicked!" & @CRLF)
                $xyPos = MouseGetPos()
                $xySpots[$clickCount][0] = $xyPos[0]
                $xySpots[$clickCount][1] = $xyPos[1]
                $clickCount += 1
        EndIf
        Sleep(100)
    Until _IsPressed("01")
EndFunc

Func _Destination()
    Local $clickCount2 = 0, $xyPosDest
    Do
        If _IsPressed("02") Then
                ConsoleWrite("Clicked!" & @CRLF)
                $xyPosDest = MouseGetPos()
                $xyDest[$clickCount2][0] = $xyPosDest[0]
                $xyDest[$clickCount2][1] = $xyPosDest[1]
                $clickCount2 += 1
        EndIf
        Sleep(100)
    Until $clickCount2 = 1
EndFunc

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Hows this for you?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Misc.au3>
#include <Array.au3>

Dim $xySpots[1][2]
Dim $xyDest[1][2]

$hGUI = GUICreate("Stacker", 494, 454)
$btnStart = GUICtrlCreateButton("Start POS", 16, 22, 81, 25)
$btnStop = GUICtrlCreateButton("Stop POS", 112, 22, 81, 25)
$btnStartDes = GUICtrlCreateButton("Start Destination", 22, 293, 89, 25)
$btnStopDes = GUICtrlCreateButton("Stop Destination", 120, 293, 89, 25)
$btnStartStack = GUICtrlCreateButton("START STACKING", 187, 371, 137, 49)
$lstXY = GUICtrlCreateListView("", 232, 22, 249, 253)
_GUICtrlListView_AddColumn($lstXY, "X", 100)
_GUICtrlListView_AddColumn($lstXY, "Y", 100)
$lst2XY = GUICtrlCreateListView("", 232, 293, 249, 50)
_GUICtrlListView_AddColumn($lst2XY, "X", 100)
_GUICtrlListView_AddColumn($lst2XY, "Y", 100)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnStart
            _MakeSpots()
            _GUICtrlListView_AddArray($lstXY, $xySpots)
        Case $btnStop
            $lstXY = GUICtrlCreateListView("", 232, 22, 249, 253)
            _GUICtrlListView_AddColumn($lstXY, "X", 100)
            _GUICtrlListView_AddColumn($lstXY, "Y", 100)
            GUISetState(@SW_SHOW)
        Case $btnStartDes
            _Destination()
            _GUICtrlListView_AddArray($lst2XY, $xyDest)
        Case $btnStopDes
            AdlibUnRegister()
            $lst2XY = GUICtrlCreateListView("", 232, 293, 249, 50)
            _GUICtrlListView_AddColumn($lst2XY, "X", 100)
            _GUICtrlListView_AddColumn($lst2XY, "Y", 100)
            GUISetState(@SW_SHOW)
        Case $btnStartStack
            _RunStack()
    EndSwitch
WEnd

Func _MakeSpots()
    Local $clickCount = 0, $xyPos
    Do
        If _IsPressed("02") Then
            ConsoleWrite("Clicked!" & @CRLF)
            $xyPos = MouseGetPos()
            Redim $xySpots[$clickCount + 1][2]
            $xySpots[$clickCount][0] = $xyPos[0]
            $xySpots[$clickCount][1] = $xyPos[1]
            $clickCount += 1
        EndIf
        Sleep(100)
    Until _IsPressed("01")
EndFunc   ;==>_MakeSpots

Func _Destination()
    Local $clickCount2 = 0, $xyPosDest
    Do
        If _IsPressed("02") Then
            ConsoleWrite("Clicked!" & @CRLF)
            $xyPosDest = MouseGetPos()
            $xyDest[$clickCount2][0] = $xyPosDest[0]
            $xyDest[$clickCount2][1] = $xyPosDest[1]
            $clickCount2 += 1
        EndIf
        Sleep(100)
    Until $clickCount2 = 1
EndFunc   ;==>_Destination

Func _RunStack()
    For $i = 0 To UBound($xySpots) - 2
        ConsoleWrite($xySpots[$i][0] & ", " & $xySpots[$i][1] & @CRLF)
        MouseMove($xySpots[$i][0], $xySpots[$i][1])
        Sleep(50)
    Next
EndFunc   ;==>_RunStack

I have no idea what the _Destination function is supposed to do.

Also, there is a lot of un-needed includes there...

Edited by JamesBrooks

Share this post


Link to post
Share on other sites

_Destination is same like _MakeSpots but for the "5" on the Sample pic. The STACK BUTTON (left click) should take the position of the Spots(1,2,3,4) and combine with Spot(5)<---this is _Destination, in this order 1,5,2,5,3,5,4,5

Share this post


Link to post
Share on other sites

_Destination is same like _MakeSpots but for the "5" on the Sample pic. The STACK BUTTON (left click) should take the position of the Spots(1,2,3,4) and combine with Spot(5)<---this is _Destination, in this order 1,5,2,5,3,5,4,5

Oh, so the _Destination co-ordinates should be placed in between the others?

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Alright, it's done. Thank Manadar for the _MergeSpotDest() function, I spent an hour and a half making a mess of it ;)

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Misc.au3>

Dim $xySpots[1][2] ; Set it small so we don't limit ourselves later
Dim $xyDest[2] ; This is fine as we don't ReDim later

$hGUI = GUICreate("Stacker", 494, 454)
$xyDesttnStart = GUICtrlCreateButton("Start POS", 16, 22, 81, 25)
$xyDesttnStop = GUICtrlCreateButton("Stop POS", 112, 22, 81, 25)
$xyDesttnStartDes = GUICtrlCreateButton("Start Destination", 22, 293, 89, 25)
$xyDesttnStopDes = GUICtrlCreateButton("Stop Destination", 120, 293, 89, 25)
$xyDesttnStartStack = GUICtrlCreateButton("START STACKING", 187, 371, 137, 49)
$lstXY = GUICtrlCreateListView("", 232, 22, 249, 253)
_GUICtrlListView_AddColumn($lstXY, "X", 100)
_GUICtrlListView_AddColumn($lstXY, "Y", 100)
$lstDest = GUICtrlCreateListView("", 232, 293, 249, 50)
_GUICtrlListView_AddColumn($lstDest, "X", 100)
_GUICtrlListView_AddColumn($lstDest, "Y", 100)
GUISetState(@SW_SHOW)

While 1
    ; I removed all of the adlib functions as you were using them incorrectly...
    ; A mess to say the least ;)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $xyDesttnStart
            _MakeSpots()
        Case $xyDesttnStop
            ; What was this?
        Case $xyDesttnStartDes
            _Destination()
        Case $xyDesttnStopDes
            ; What was this?
        Case $xyDesttnStartStack
            _MergeSpotDest()
            _RunStack()
    EndSwitch
WEnd

Func _MakeSpots()
    Local $arrStacklickCount = 0, $xyPos
    Do
        If _IsPressed("02") Then
            $xyPos = MouseGetPos()
            ReDim $xySpots[$arrStacklickCount + 1][2]
            $xySpots[$arrStacklickCount][0] = $xyPos[0]
            $xySpots[$arrStacklickCount][1] = $xyPos[1]
            _GUICtrlListView_AddItem($lstXY, $xySpots[$arrStacklickCount][0])
            _GUICtrlListView_AddSubItem($lstXY, $arrStacklickCount, $xySpots[$arrStacklickCount][1], 1)
            $arrStacklickCount += 1
        EndIf
        Sleep(100)
    Until _IsPressed("01")
    ConsoleWrite("->Stopped processing clicks" & @CRLF)
EndFunc   ;==>_MakeSpots

Func _Destination()
    Local $arrStacklickCount2 = 0, $xyPosDest
    Do
        If _IsPressed("02") Then
            $xyPosDest = MouseGetPos()
            $xyDest[0] = $xyPosDest[0]
            $xyDest[1] = $xyPosDest[1]
            _GUICtrlListView_AddItem($lstDest, $xyDest[0])
            _GUICtrlListView_AddSubItem($lstDest, 0, $xyDest[1], 1)
            $arrStacklickCount2 = 1
        EndIf
        Sleep(100)
    Until $arrStacklickCount2 = 1
    ConsoleWrite("->Stopped processing destination clicks" & @CRLF)
EndFunc   ;==>_Destination

Func _RunStack()
    For $i = 0 To UBound($xySpots) - 1 ; This was wrong before
        ConsoleWrite($xySpots[$i][0] & ", " & $xySpots[$i][1] & @CRLF)
        MouseMove($xySpots[$i][0], $xySpots[$i][1])
        Sleep(50)
    Next
EndFunc   ;==>_RunStack

Func _MergeSpotDest()
    $l = UBound($xySpots)
    $m = $l * 2
    Dim $arrStack[$m][2]
    For $i = 0 To $l - 1
        $arrStack[$i * 2][0] = $xySpots[$i][0]
        $arrStack[$i * 2][1] = $xySpots[$i][1]
    Next
    For $i = 1 To $m - 1 Step 2
        $arrStack[$i][0] = $xyDest[0]
        $arrStack[$i][1] = $xyDest[1]
    Next
    $xySpots = $arrStack
EndFunc   ;==>_MergeSpotDest

Couple of changes:

  • $xyDest is now a one dimensional array, the first [0] dimension is redundant.
  • I've changed the way that the co-ordinates are added to the list, now they're added each time the user right clicks.
  • I fixed a dodgy loop, that didn't really make sense.
  • I've removed the unneeded includes.
  • Also, I removed the Stop button code because I don't get why they were there.
Edited by JamesBrooks

Share this post


Link to post
Share on other sites

What can i say guys, thanks a lot it`s working very fine. A little modification i made i put the left click action and mouse speed on "_RunStack".

The Stop button it was made for clear the List Boxes. (i couldn`t find the command to do that).

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Misc.au3>

Dim $xySpots[1][2] 
Dim $xyDest[2]  

$hGUI = GUICreate("Stacker", 494, 454)
$xyDesttnStart = GUICtrlCreateButton("Start POS", 16, 22, 81, 25)
$xyDesttnStop = GUICtrlCreateButton("Stop POS", 112, 22, 81, 25)
$xyDesttnStartDes = GUICtrlCreateButton("Start Destination", 22, 293, 89, 25)
$xyDesttnStopDes = GUICtrlCreateButton("Stop Destination", 120, 293, 89, 25)
$xyDesttnStartStack = GUICtrlCreateButton("START STACKING", 187, 371, 137, 49)
$lstXY = GUICtrlCreateListView("", 232, 22, 249, 253)
_GUICtrlListView_AddColumn($lstXY, "X", 100)
_GUICtrlListView_AddColumn($lstXY, "Y", 100)
$lstDest = GUICtrlCreateListView("", 232, 293, 249, 50)
_GUICtrlListView_AddColumn($lstDest, "X", 100)
_GUICtrlListView_AddColumn($lstDest, "Y", 100)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $xyDesttnStart
            _MakeSpots()
        Case $xyDesttnStop
            ; The Stop button i want to clear the LIST BOX
        Case $xyDesttnStartDes
            _Destination()
        Case $xyDesttnStopDes
            ; The Stop button i want to clear the LIST BOX
        Case $xyDesttnStartStack
            _MergeSpotDest()
            _RunStack()
    EndSwitch
WEnd

Func _MakeSpots()
    Local $arrStacklickCount = 0, $xyPos
    Do
        If _IsPressed("02") Then
            $xyPos = MouseGetPos()
            ReDim $xySpots[$arrStacklickCount + 1][2]
            $xySpots[$arrStacklickCount][0] = $xyPos[0]
            $xySpots[$arrStacklickCount][1] = $xyPos[1]
            _GUICtrlListView_AddItem($lstXY, $xySpots[$arrStacklickCount][0])
            _GUICtrlListView_AddSubItem($lstXY, $arrStacklickCount, $xySpots[$arrStacklickCount][1], 1)
            $arrStacklickCount += 1
        EndIf
        Sleep(100)
    Until _IsPressed("01")
    ConsoleWrite("->Stopped processing clicks" & @CRLF)
EndFunc   

Func _Destination()
    Local $arrStacklickCount2 = 0, $xyPosDest
    Do
        If _IsPressed("02") Then
            $xyPosDest = MouseGetPos()
            $xyDest[0] = $xyPosDest[0]
            $xyDest[1] = $xyPosDest[1]
            _GUICtrlListView_AddItem($lstDest, $xyDest[0])
            _GUICtrlListView_AddSubItem($lstDest, 0, $xyDest[1], 1)
            $arrStacklickCount2 = 1
        EndIf
        Sleep(100)
    Until $arrStacklickCount2 = 1
    ConsoleWrite("->Stopped processing destination clicks" & @CRLF)
EndFunc   

Func _RunStack()
    For $i = 0 To UBound($xySpots) - 1 
        ConsoleWrite($xySpots[$i][0] & ", " & $xySpots[$i][1] & @CRLF)
        MouseMove($xySpots[$i][0], $xySpots[$i][1],1) ; I PUT SPEED ON THE MOUSE MOVE
        MouseDown("left") ; and THE LEFT CLICK
        MouseUp("left")
        Sleep(50)
    Next
EndFunc   

Func _MergeSpotDest()
    $l = UBound($xySpots)
    $m = $l * 2
    Dim $arrStack[$m][2]
    For $i = 0 To $l - 1
        $arrStack[$i * 2][0] = $xySpots[$i][0]
        $arrStack[$i * 2][1] = $xySpots[$i][1]
    Next
    For $i = 1 To $m - 1 Step 2
        $arrStack[$i][0] = $xyDest[0]
        $arrStack[$i][1] = $xyDest[1]
    Next
    $xySpots = $arrStack
EndFunc

Great work thanks a lot again and sorry for making u spend some time on this problem. I learn a lot from this at least some commands.

Share this post


Link to post
Share on other sites

Voilà.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Misc.au3>

Dim $xySpots[1][2]
Dim $xyDest[2]

$hGUI = GUICreate("Stacker", 494, 454)
$xyDesttnStart = GUICtrlCreateButton("Start POS", 16, 22, 81, 25)
$xyDesttnStop = GUICtrlCreateButton("Stop POS", 112, 22, 81, 25)
$xyDesttnStartDes = GUICtrlCreateButton("Start Destination", 22, 293, 89, 25)
$xyDesttnStopDes = GUICtrlCreateButton("Stop Destination", 120, 293, 89, 25)
$xyDesttnStartStack = GUICtrlCreateButton("START STACKING", 187, 371, 137, 49)
$lstXY = GUICtrlCreateListView("", 232, 22, 249, 253)
_GUICtrlListView_AddColumn($lstXY, "X", 100)
_GUICtrlListView_AddColumn($lstXY, "Y", 100)
$lstDest = GUICtrlCreateListView("", 232, 293, 249, 50)
_GUICtrlListView_AddColumn($lstDest, "X", 100)
_GUICtrlListView_AddColumn($lstDest, "Y", 100)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $xyDesttnStart
            _MakeSpots()
        Case $xyDesttnStop
            $xySpots = ""
            $xyDest = ""
            _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($lstXY))
            _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($lstDest))
        Case $xyDesttnStartDes
            _Destination()
        Case $xyDesttnStopDes
            $xySpots = ""
            $xyDest = ""
            _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($lstXY))
            _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($lstDest))
        Case $xyDesttnStartStack
            _MergeSpotDest()
            _RunStack()
    EndSwitch
WEnd

Func _MakeSpots()
    Local $arrStacklickCount = 0, $xyPos
    Do
        If _IsPressed("02") Then
            $xyPos = MouseGetPos()
            ReDim $xySpots[$arrStacklickCount + 1][2]
            $xySpots[$arrStacklickCount][0] = $xyPos[0]
            $xySpots[$arrStacklickCount][1] = $xyPos[1]
            _GUICtrlListView_AddItem($lstXY, $xySpots[$arrStacklickCount][0])
            _GUICtrlListView_AddSubItem($lstXY, $arrStacklickCount, $xySpots[$arrStacklickCount][1], 1)
            $arrStacklickCount += 1
        EndIf
        Sleep(100)
    Until _IsPressed("01")
    ConsoleWrite("->Stopped processing clicks" & @CRLF)
EndFunc

Func _Destination()
    Local $arrStacklickCount2 = 0, $xyPosDest
    Do
        If _IsPressed("02") Then
            $xyPosDest = MouseGetPos()
            $xyDest[0] = $xyPosDest[0]
            $xyDest[1] = $xyPosDest[1]
            _GUICtrlListView_AddItem($lstDest, $xyDest[0])
            _GUICtrlListView_AddSubItem($lstDest, 0, $xyDest[1], 1)
            $arrStacklickCount2 = 1
        EndIf
        Sleep(100)
    Until $arrStacklickCount2 = 1
    ConsoleWrite("->Stopped processing destination clicks" & @CRLF)
EndFunc

Func _RunStack()
    For $i = 0 To UBound($xySpots) - 1
        ConsoleWrite($xySpots[$i][0] & ", " & $xySpots[$i][1] & @CRLF)
        MouseMove($xySpots[$i][0], $xySpots[$i][1],1) ; I PUT SPEED ON THE MOUSE MOVE
        ;MouseDown("left") ; and THE LEFT CLICK
        ;MouseUp("left")
        MouseClick("left") ; Better to just click
        Sleep(50)
    Next
EndFunc

Func _MergeSpotDest()
    $l = UBound($xySpots)
    $m = $l * 2
    Dim $arrStack[$m][2]
    For $i = 0 To $l - 1
        $arrStack[$i * 2][0] = $xySpots[$i][0]
        $arrStack[$i * 2][1] = $xySpots[$i][1]
    Next
    For $i = 1 To $m - 1 Step 2
        $arrStack[$i][0] = $xyDest[0]
        $arrStack[$i][1] = $xyDest[1]
    Next
    $xySpots = $arrStack
EndFunc

  • You need to clear the arrays by setting them to nothing
  • I removed your MouseDown and MouseUp functions and just replaced them with MouseClick("left")
  • You can empty a listview by _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle(CONTROL TO LISTVIEW))

Share this post


Link to post
Share on other sites

Thanks. Great work. The script works very very good.

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