Array for mouse coordinates.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JaminRoyale1
Posts: 6
Joined: 09 May 2020, 22:56

Array for mouse coordinates.

14 Sep 2020, 16:01

Hello,

Just a quick question. I will create an array in a text file to use in AHK to move the mouse until it finds the desired object.

Im just wondering if i can make one file or if i need two. one for x and one for y

Or can i just do

x1, y1
x2, y2

and so on.

Also if there an easier way to save both coordinates in a single variable instead of using two like ive been doing?
Thanks in advance
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Array for mouse coordinates.

14 Sep 2020, 17:13

If you're looking for pixels or images, you can do that without moving the mouse at all. See documentation for PixelGetColor and ImageSearch. I'm not sure what you mean about making files.
JaminRoyale1
Posts: 6
Joined: 09 May 2020, 22:56

Re: Array for mouse coordinates.

14 Sep 2020, 17:20

depending on whats under the mouse a description shows on the right side so i will be searching on the right side of the screen that changes as the mouse moves.

I want to move the mouse in a rotating outwards square pattern starting from the center of the screen. After reading about arrays and how to implement them, i thought it made sense to create a text file with my desired mouse coordinates one after the other.
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Array for mouse coordinates.

14 Sep 2020, 18:19

Sure, you could use a text file, an AHK array in a script, or a formula if the coordinates can be represented by a systematic pattern.

https://www.autohotkey.com/docs/commands/LoopReadFile.htm
JaminRoyale1
Posts: 6
Joined: 09 May 2020, 22:56

Re: Array for mouse coordinates.

14 Sep 2020, 20:13

yes exactly, but my question remains.

can i put both x and y coordinates on the same line? everytime ive used mouse coordinates ive stored the x and y values in different variables but i dont like that. it also means i need an x array and y array.
User avatar
Chunjee
Posts: 1419
Joined: 18 Apr 2014, 19:05
Contact:

Re: Array for mouse coordinates.

15 Sep 2020, 05:48

how about saving each element as an object with x and y properties? I do this often:

Code: Select all

allCoords := [{x:200, y:100}, {x:1000, y:800}]

for _, obj in allCoords {
	msgbox, % obj.x " and " obj.y
}
JaminRoyale1
Posts: 6
Joined: 09 May 2020, 22:56

Re: Array for mouse coordinates.

15 Sep 2020, 09:20

Chunjee wrote:
15 Sep 2020, 05:48
how about saving each element as an object with x and y properties? I do this often:

Code: Select all

allCoords := [{x:200, y:100}, {x:1000, y:800}]

for _, obj in allCoords {
	msgbox, % obj.x " and " obj.y
}
This is perfect thank you. i will implement this
User avatar
Chunjee
Posts: 1419
Joined: 18 Apr 2014, 19:05
Contact:

Re: Array for mouse coordinates.

15 Sep 2020, 09:44

Incase needed; here is how to create objects and push them onto an array; in this case when an imagesearch successfully finds an x and y to add

Code: Select all

allCoords := []

ImageSearch, x, y, 100, 100, 900, 900, % A_ScriptDir "\imgage.png"
if (x) {
	obj := {}
	obj.x := x
	obj.y := y
	allCoords.push(obj)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, DiegoSouto, mikeyww, Rohwedder, Sniperman, Swiftly9767 and 381 guests