Jump to content

How to store mouse coordinate into 2D array?


Recommended Posts

Hello everyone,

First of all, i just start to learning this language by myself, via help file and google search!

So my lame question is, how i can store the mouse coordinate into a 2D array multiple times?

My friend ask me to make an auto clicker script for him. If i simple codeing the mouse coordinates it is work fine, but every time if the mouse coordinates will change, need to change them in code as well. So i decide to make a function for recording it till it needed, then i can use that array in a loop for make the mouse cursor move and click on right position.

Code:

#include <Array.au3>

HotKeySet("{F1}", "TogglePause")
HotKeySet("{F2}", "RecordingMouseCoordinate")
HotKeySet("{F3}", "Display")
HotKeySet("{F5}", "RunScript")
HotKeySet("{ESC}", "Terminate")

Global $Paused

Local $MouseX, $MouseY
Global $MouseRecord[1][2], $MouseRecordXY[1][2]
Local $i = 0

MsgBox(0, "Info", "F1 - Pause" & @LF & "F2 - Record coordinate" & @LF & "F3 - Display Coordinates" & @LF & "F5 - Run the Script" & @LF & "ESC - Exit script")

While 1
    Sleep(100)
WEnd

Func RunScript()
    Do
#cs
        ; loop for make mouse work with stored coordinates // Something like this but it is not work, cause of error what i will fix when i have the array for it
        For $x = 1 To $MouseRecordXY[$x]
            MouseClick("left", $MouseRecordXY[$x][0], $MouseRecordXY[$x][1], 1, 1)
        Next
#ce
    Until $i = 1

EndFunc   ;==>RunScript

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("Script is Paused", 0, 0)
EndFunc   ;==>TogglePause

Func RecordingMouseCoordinate()
    Local $MousePos = MouseGetPos()

    $MouseX = $MousePos[0]
    $MouseY = $MousePos[1]

    ToolTip("Mouse Coordinate - " & $MousePos[0] & " x " & $MousePos[1], 0, 0)

    $MouseRecord[0][0] = $MousePos[0]
    $MouseRecord[0][1] = $MousePos[1]

    #cs
        _ArrayAdd($MouseRecordXY, $MouseRecord) ; tried to add 2D array into another 2D array to store the coordinates in $MouseRecordXY array
        _ArrayConcatenate($MouseRecordXY, $MouseRecord) ; Non of them want to work or i am just simple lame :)
        _ArrayAdd($MouseRecordXY[0][0], $MouseX)
        _ArrayAdd($MouseRecordXY[0][1], $MouseY)
    #ce


    _ArrayDisplay($MouseRecordXY, "")
    ;_ArrayDisplay($MouseRecord, "");this one is working

EndFunc   ;==>RecordingMouseCoordinate

Func Display()

EndFunc   ;==>Display

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Other question, how i can use _ArrayAdd for adding 2D array into another 2d array? Or shell i use this _ArrayConcatenate instead of _ArrayAdd?

Unfortuantely AutoIT help have no examples for / with multi dimensional arrays what i need.

Till now i tried many crazy different way to make it work but keep geting different errors. :(

Probably the solution is simple, but i am not seeing it, since i am beginer on programing and still have a lot of thing to try to understand.

As i read somewhere AutoIT can use send order only on the active window. Do we have maybe any way to use it on multi clients with out activateing the windows itself? And / Or can we use it on 2 window at same time?

I would be happy if i get little explain on help, how does it work, or what i did wrong, so i can learn from it.

Tricky,

Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Can you please tell us which program you try to automate with your auto-clicker? Working with mouse coordinates isn't very reliable. It's dependant on screen resolution and window coordinates.

Most of the time there more reliable ways to automate an application.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thank You,

He wana use it for a game called dekaron for talking with NPC (non player character) to picking up replaceable quests or conversation. With coded coordinates worked fine. I know MouseGetPos Screen (resolution) for that i can check the actual screen size with:

Func ScreenSize()
    Local $ScreenSizeWidth
    Local $ScreenSizeHeight

    $ScreenSizeWidth = @DesktopWidth
    $ScreenSizeHeight = @DesktopHeight
    MsgBox(0, "Screen Size", StringFormat("Width %u Hight %u", $ScreenSizeWidth, $ScreenSizeHeight))
EndFunc   ;==>ScreenSize

And found on forum how to get mouse pos on specificated window. I have trouble with adding 2d array into another 2d array. Can not understand why it is not working, or how it have to work. (dont have the require knowleadge yet :-/)

Tricky,

Edited by TrickyDeath

Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

Link to comment
Share on other sites

The next step I suggest is to read the forum rules.

A link can be found in the lower right corner of each page.

Game automation of any kind is prohibited here. Sorry.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

TrickyDeath,

water is quite right - please read the Forum rules (the link is also at bottom right of each page) - particularly the bit about not discussing game automation - before you post again. Thread locked. :naughty:

But welcome to the AutoIt forum - and see you soon with a legitimate question I hope. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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