Jump to content

Script that uses a lot of mouse click coordinates


Go to solution Solved by Nine,

Recommended Posts

I'm writing a script that uses a lot of specific mouse clicks to automate tasks on my browser, server system, and email software for work.
Sometimes the system gets updated or someone drags a handle to the left or right and I have to put in new mouse click coordinates.

It would be a lot more easy to label them and put them in some sort of ini file, but then i have to load every X and Y (and sometimes mouse speed) into a variable
when loading the script.

How would you guys go about such a script, any ideas on how to store and load lot's of click coordinates from a file?
There are some pixel color checks, sleeps and other code between the mouse clicks too..

Ideas i had so far:
- string replace new coordinates in the main script with another autoit script that uses a crosshair to show every mouse position.
- manually write an ini file and load every X, Y, Speed into a huge number of variables: $Searchinput_X = iniread...., $Searchinput_Yiniread...., $Searchinput_Speed = iniread....
- split a textfile line by line into an array and ignore labels that begin with ";" for example (a bit like a custom ini file)

These all seem somewhat tedious i guess..

Link to comment
Share on other sites

  • Solution

How about extracting all MouseClick from the au3 file and convert them into a ini file (assuming you can associate each MouseClick to a unique name : maybe by having a comment after the MouseClick naming the action).  Once this is done, you could read the ini file into the new Map var type. Each entry would be a string of three elements (e.g. X|Y|Speed).

Link to comment
Share on other sites

20 minutes ago, Nine said:

How about extracting all MouseClick from the au3 file and convert them into a ini file (assuming you can associate each MouseClick to a unique name : maybe by having a comment after the MouseClick naming the action).  Once this is done, you could read the ini file into the new Map var type. Each entry would be a string of three elements (e.g. X|Y|Speed).

You mean like an array of strings "x|y|s" and then split them every time by "|"?

Link to comment
Share on other sites

Yes.  You can create a MouseClickEx function that would do that for each action.  You would only need to pass the name of the MouseClick, and it would do all (search map, get the 3 param and click the mouse accordingly).

Link to comment
Share on other sites

2 minutes ago, Nine said:

Yes.  You can create a MouseClickEx function that would do that for each action.  You would only need to pass the name of the MouseClick, and it would do all (search map, get the 3 param and click the mouse accordingly).

That's a good idea actually :)

Some kind of lookup table, nice!

Link to comment
Share on other sites

Link to comment
Share on other sites

2 hours ago, Nine said:

You could add more info into the ini file : button, sleep time after click, number of click, etc...  It would be a very general clicker that way.

unfortunately "maps" are still in beta and unstable..
i have to make some sort of multidimensional array instead, the thing is.. i use filereadtoarray to get an array of elements from a file, those lines need to be split and after that i need to put them all together into a multidimensional array. it's funny, i need a 2D array and a normal array in a loop to fill up the final multidimensional array :p

Local $n = 0, $x = 1, $y = 2, $s = 3
Local $file = FileReadToArray('nxys.txt')
Local $map[@extended][4]
$map_max = @extended-1

For $i = 0 To $map_max
    $split = StringSplit($file[$i], '|', 3)
    $map[$i][$n] = $split[$n]
    $map[$i][$x] = $split[$x]
    $map[$i][$y] = $split[$y]
    $map[$i][$s] = $split[$s]
Next

Func map_mouse_move($name)
    Local $i
    For $i = 0 To $map_max
        If $map[$i][$n] = $name Then
            MouseMove($map[$i][$x], $map[$i][$y], $map[$i][$s])
            Return True
        EndIf
    Next
EndFunc

map_mouse_move('test')

nxys.txt:

name|x|y|speed
test|50|100|100

Link to comment
Share on other sites

55 minutes ago, TheAutomator said:

unfortunately "maps" are still in beta and unstable.

Wrong, it is prod in 3.3.16.0 and it is stable.

But if array is what you understand more, i guess you should go ahead with it, but you are missing a good opportunity to learn a new approach.

Link to comment
Share on other sites

1 minute ago, Nine said:

Wrong, it is prod in 3.3.16.0 and it is stable.

But if array is what you understand more, i guess you should go ahead with it, but you are missing a good opportunity to learn a new approach.

oh really? :blink: i have v3.3.14.5, guess it's not in my version (gonna update now)

Link to comment
Share on other sites

Global $position[]
Func position($label, $x, $y, $speed = 10)
    Local $sub[]
    $sub.x = $x
    $sub.y = $y
    $sub.s = $speed
    $position[$label] = $sub
EndFunc

;========================================

;-----FIREFOX-----

position('refresh'          , 95, 65)
position('downloads'        , 1823, 63)
position('pdf drag'         , 1608, 121)
position('pdf drop'         , 1368, 505)

;=================================================

Func mouse_move($name)
    Local $key = $position[$name]
    MouseMove($key.x, $key.y, $key.s)
EndFunc

Func mouse_click($name)
    Local $key = $position[$name]
    MouseClick('main', $key.x, $key.y, 1, $key.s)
EndFunc

mouse_move('refresh')

I included 4 positions as an example, would it be a good idea to read the keys to a variable?
or should I do "mousemove($position[$name].x, $position[$name].y....)"?

If i think correctly, the example code that stores a temp "key" variable would be less work for the cpu right?

Edited by TheAutomator
Link to comment
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
 Share

×
×
  • Create New...